当前位置:网站首页>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()
边栏推荐
- 6-10 二分查找(20分)
- JSON serialization and deserialization using Jackson API in Scala
- MySQL 原理与优化:Update 优化
- Today's bug, click on the bug that the Windows dynamic wallpaper disappears in the win10 taskbar, and no solution has been found yet.
- 7-2 乒乓人训练大师(双指针)
- JVM基本结构
- Win11连接投影仪没反应怎么解决?
- 【ARK UI】HarmonyOS ETS的引导页的实现
- 803. 区间合并(贪心)左端点、右端点排序均可
- 网络拓扑管理
猜你喜欢
![[Image segmentation] Image segmentation based on cellular automata with matlab code](/img/f7/2fd7dfc0bc59bf3492b304c69bd4c7.png)
[Image segmentation] Image segmentation based on cellular automata with matlab code

Interface test advanced interface script using -apipost (pre/post execution script)
![[Image dehazing] Image dehazing based on color attenuation prior with matlab code](/img/ae/d6d36671804fadae548464496f28d6.png)
[Image dehazing] Image dehazing based on color attenuation prior with matlab code

AIRIOT答疑第8期|AIRIOT的金字塔服务体系是如何搞定客户的?

NPDP|传统行业产品经理如何进行能力提升?

选择是公有云还或是私有云,这很重要吗?

Keil5退出仿真调试卡死的解决办法

基于GAMS的电力系统优化分析

从企业的视角来看,数据中台到底意味着什么?

Consul Introduction and Installation
随机推荐
openssl查看证书信息
Biotin-PEG4-IC(TFP ester/amine/NHS Ester/azide)特性分享
MySql main performance indicators description
NPDP|传统行业产品经理如何进行能力提升?
罗克韦尔Rockwell Automation EDI 项目
servlet映射路径匹配解析
开发模式对测试的影响
钻石价格预测的ML全流程!从模型构建调优道部署应用!
1720. 解码异或后的数组
JVM内存和垃圾回收-11.执行引擎
西安凯新(CAS:2408831-65-0)Biotin-PEG4-Acrylamide 特性
FPGA工程师面试试题集锦71~80
QoS服务质量八拥塞避免
PG中的Index-Only Scans解密
智能安防产品公司及产品
陕西CAS:1244028-50-9_Biotin-PEG3-SCO-PPh3 固体
【FAQ】【Push Kit】 华为怎么设置角标
pip3升级到22.2.2
【ARK UI】HarmonyOS ETS的引导页的实现
【HMS core】【FAQ】Account Kit、push Kit典型问题合集1