|

url传参方式 普通传参方式 @app.route('/p/<id>/')
def article_detail(id):
return '你访问的文章第%s篇'%id
指定参数类型 有以下几种类型: 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 flask import Flask,request
@app.route('/tieba/')
def tieba():
wd = request.args.get('wd')
return '获取的参数的是%s'%wd |