当前位置:网站首页>flask生成路由的2种方式和反向生成url
flask生成路由的2种方式和反向生成url
2022-08-10 18:39:00 【低调说】
from flask import Flask, request, render_template, redirect, url_for
app = Flask(__name__)
# 配置文件
app.config.from_object("settings.BaseConfig")
# 第一种添加路由的方式
@app.route('/')
def index():
return "第一种添加路由的方式"
def test():
return "第二种添加路由的方式"
# 第二种添加路由的方式
app.add_url_rule('/test', view_func=test)
@app.route('/point_url', methods=['GET', 'POST'], endpoint='point')
def point():
u = url_for('point') # 反向生成url,默认不起别名,就是函数名
print(u)
return 'flask里的endpoint相当于django路由里面的name'
@app.route('/point2_url', methods=['GET', 'POST'])
def point2():
u2 = url_for('point2') # 反向生成url,默认不起别名,就是函数名
print(u2)
return 'flask里的endpoint相当于django路由里面的name'
if __name__ == '__main__':
app.run()
边栏推荐
- 面试题 04.12. 求和路径-dfs+辅助数组法
- Biotin-PEG4-IC(TFP ester/amine/NHS Ester/azide)特性分享
- Consul Introduction and Installation
- 基于 RocksDB 实现高可靠、低时延的 MQTT 数据持久化
- FPGA工程师面试试题集锦71~80
- redis.exceptions.DataError: Invalid input of type: ‘dict‘. Convert to a byte, string or number first
- 【图像去雾】基于颜色衰减先验的图像去雾附matlab代码
- 类型和id对应的两个数组
- 第四届“传智杯”全国大学生IT技能大赛(初赛A组) 补题
- Keras deep learning combat (17) - image segmentation using U-Net architecture
猜你喜欢
随机推荐
003-序列图(一)
请问下在datastream中用flinkcdc怎么设置jdbc的参数useSSL=false呀
开源一夏 | mysql5.7 安装部署 -二进制安装
第15章_锁
Redis命令---key篇 (超全)
剑指 Offer II 034. 外星语言是否排序-辅助数组法
基于GAMS的电力系统优化分析
IoU、GIoU、DIoU、CIoU四种损失函数总结
redis.exceptions.DataError: Invalid input of type: ‘dict‘. Convert to a byte, string or number first
【深度学习前沿应用】图像风格迁移
状态压缩dp蒙德里安的梦想
905. 区间选点(贪心)
谈谈宝石方块游戏中的设计
友邦人寿可观测体系设计与落地
redis 事件
云渲染的应用正在扩大,越来越多的行业需要可视化服务
【Knowledge Sharing】What is SEI in the field of audio and video development?
从企业的视角来看,数据中台到底意味着什么?
让mixin为项目开发助力【及递归优化新尝试】
【HMS core】【FAQ】AR Engine、Analytics Kit、Video Editor Kit、Image Kit、Map Kit典型问题合集2