flaskurl传参用法

from flask import Flask,request


app = Flask(__name__)


@app.route("/")
def index():
    return "hello world"


#url中带参数怎么传递
@app.route('/article/<id>/')
def article(id):

    return "article:{}".format(id)

#url中限制整数
@app.route('/author/<int:id>/')
def detail_author(id):
    return '作者详情:{}'.format(id)

#url中限制浮点数
@app.route('/price/<float:id>')
def price(id):
    return 'salary:{}'.format(id)

#url中用path可以匹配分隔符
@app.route('/book/<path:id>')
def detail_book(id):
    return '书籍详情页:{}'.format(id)
#uuid url的用法
@app.route('/user/<uuid:user_id>')
def user_detail(user_id):
    return '用户个人详情页:%s'%user_id
import uuid
print(uuid.uuid1())

#any可以匹配多个
@app.route("/<any(blog,user):url_path>/<int:id>/")
def detail(url_path,id):
    if url_path == "blog":
        return "博客详情页:%s"%id
    else:
        return '用户详情页:%s'%id


#通过?的方式来传递参数
@app.route('/d/')
def search():
    wd = request.args.get('wd')
    return "根据关键字来查询:%s"%wd

 #如果是多参数来请求的话

这个后台参数该怎么接受

@app.route('/d/')
def search():
    wd = request.args.get('wd')
  #这里再接受一个参数
  ie = request.ags.get('ie')
return "根据关键字来查询:%s-%s"%(wd,ie)
if __name__ == '__main__':
    app.run(debug=True)

原文地址:https://www.cnblogs.com/wuheng-123/p/9662181.html