zoukankan      html  css  js  c++  java
  • 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)
    
    
  • 相关阅读:
    pgsql 记录
    tomcat下放两个spring boot项目
    nigex 反向代理
    tomcat7里放springboot
    postgresql 建表语句
    从最大似然到EM算法浅解(转载)
    深度学习资料
    【vuejs小项目——vuejs2.0版本】组件化的开发方式
    【vuejs小项目——vuejs2.0版本】单页面搭建
    如何关闭eslint
  • 原文地址:https://www.cnblogs.com/wuheng-123/p/9662181.html
Copyright © 2011-2022 走看看