普通传参方式
@app.route('/p/<id>/') def article_detail(id): return '你访问的文章第%s篇'%id
www#gaodaima.com来源gaodai#ma#com搞@代~码网搞代码指定参数类型
有以下几种类型:
string:默认的数据类型
int:接受整形
float:浮点型
path:和string的类似,但是接受斜杠
any:可以指定多个路径
uuid:只接受uuid字符串
相关推荐:《Python相关教程》
(1)any
@app.route('/<any(blog,user):url_path>/<id>') def detail(url_path,id): if url_path == 'blog': return '博客详情%s'%id else: return '用户详情%s'%id
(2)path
@app.route('/article/<path:test>/') def test_article(test): return 'test_article:{}'.format(test)
获取参数
from <a href="https://www.gaodaima.com/tag/flask" title="查看更多关于flask的文章" target="_blank">flask</a> import Flask,request @app.route('/tieba/') def tieba(): wd = request.args.get('wd') return '获取的参数的是%s'%wd
来源:搞代码网:原文地址:https://www.gaodaima.com