python flask中动态URL规则详解
作者:我不喜欢这个世界 时间:2021-08-18 15:51:23
URL是可以添加变量部分的,
把类似的部分抽象出来,
比如:
@app.route('/example/1/')
@app.route('/example/2/')
@app.route('/example/3/')
def example(id):
return 'example:{ }'.format(id)
可以抽象为:
@app.route('/example/<id>/')
def wxample(id):
return 'example:{ }'.format(id)
尖括号中的内容是动态的,id作为参数获得,
此时默认id为字符串类型
我们可以指定参数类型,
比如:
string:指定任何没有斜杠‘/'的文本(默认)
int:接受整数
float:同int,但是接受浮点数
path:和默认的很相似,但是可以接受斜杠
uuid:只接受uuid字符串
any:可以指定多种路径,但是需要传入参数
比如:
@app.route('/any(a,b)':content_name/)
访问/a/和访问/b/都符合这个规则,/a/对应的content_name就是a.
来源:https://blog.csdn.net/m0_38124502/article/details/78680368
标签:python,flask,URL
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实战之Scrapy框架爬虫爬取微博热搜
2022-07-08 02:09:50
![](https://img.aspxhome.com/file/2023/2/89012_0s.png)
python文件操作相关知识点总结整理
2023-05-09 02:17:42
使用ACCESS做网络版程序的四种解决方案
2009-01-14 16:22:00
asp OpenTextFile文本读取与写入实例代码
2011-04-15 11:00:00
pytorch model.cuda()花费时间很长的解决
2021-12-08 08:02:06
![](https://img.aspxhome.com/file/2023/3/86143_0s.jpg)
python实现从尾到头打印单链表操作示例
2021-12-20 00:09:32
用滤镜使网页图片产生旋转效果
2007-11-03 11:36:00
![](https://img.aspxhome.com/file/UploadPic/20072/20072311370301s.jpg)
python识别图像并提取文字的实现方法
2023-06-07 18:36:36
![](https://img.aspxhome.com/file/2023/3/85383_0s.jpg)
实用技巧:优化SQL Server数据库查询方法
2009-02-04 13:46:00
Oracle性能究极优化 下
2010-07-30 13:25:00
python人工智能tensorflow常用激活函数Activation Functions
2023-08-01 12:45:02
![](https://img.aspxhome.com/file/2023/6/67236_0s.png)
python自动截取需要区域,进行图像识别的方法
2021-05-14 11:04:42
初步探究Python程序的执行原理
2022-11-06 10:30:20
![](https://img.aspxhome.com/file/2023/7/82747_0s.png)
Python实现的NN神经网络算法完整示例
2023-10-06 04:30:41
![](https://img.aspxhome.com/file/2023/2/63542_0s.png)
python 合并表格详解
2023-09-08 16:03:48
流行WEB开发语言比较之ASP篇
2007-12-23 17:23:00
PyCharm 2021.2 (Professional)调试远程服务器程序的操作技巧
2023-08-23 20:48:17
![](https://img.aspxhome.com/file/2023/8/75118_0s.png)
python 并发下载器实现方法示例
2022-03-31 10:46:00
JavaScript模板解析演示实例
2009-10-19 23:16:00
JavaScript 中的 Base64 编码(一):Encode
2010-07-23 10:16:00