<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 07 URL中兩種方式傳參 ## URL與視圖函數的映射 ### 傳遞參數 傳遞參數的語法是:"/&lt;參數名&gt;/",然后在視圖函數中,也要定義同名的參數 &lt;converter:variable\_name&gt;,其中converter就是類型名稱 string:默認的數據類型,接受沒有任何斜杠"\/"的文本 int:接受整型 float:接受浮點類型 path:和string的類似,但是接受斜杠 uuid:只接受uuid字符串\(唯一,長度過長\)。'uuid'只能接受符合'uuid'的字符擦混,'uuid'是一個唯一的字符串,用于做表的主鍵 ```text import uuid print(uuid.uuid4()) @app.route('/u/<uuid:user_id>/') def user_detail(user_id): return "用戶個人中心頁面:%s" % user_id ``` ![](https://box.kancloud.cn/12410a1aa595d8c18c4531c75ba53cbc_997x205.png) any:可以指定多種路徑。'any'數據類型可以在一個"url"中的指定多個路徑 通過一個例子來進行說明 ```text from flask import Flask, config app = Flask(__name__) @app.route('/<any(blog,user):url_path>/<id>') def detail(url_path,id): if url_path == "blog": return "博客詳情:%s" % id else: return "用戶詳情:%s" % id if __name__ == '__main__': app.run(debug=True) ``` ![](https://box.kancloud.cn/314f4dea85f2e46faccd9bada352bc1e_360x220.png) ![](https://box.kancloud.cn/42b80a0f36d8bf4d12fb58716f962320_472x205.png) ## 接收用戶傳遞的參數 1. 第一種:使用path的形式\(將參數嵌入到路徑中\) 2. 第二種:使用查詢字符串的方式,就是通過"?key=value"的形式傳遞的 ```text @app.route('/d/') def d(): wd = request.args.get("wd") return "查詢字符串參數:%s" % wd ``` ![](https://box.kancloud.cn/50caee13f7b987ca8b76197ab19d08dd_386x201.png) 3.如果頁面要做"SEO"優化,推薦使用"path"形式 如果不在搜索引擎優化,就是用查詢字符串 ```text from flask import Flask,request app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' @app.route('/list/') def article_list(): return 'article_list' # @app.route('/article/<article_id>/') # def article_detail(article_id): # return 'successful,位置%s' % article_id # @app.route('/p/<int:article_id>') @app.route('/p/<float:article_id>') def article_detail(article_id): return 'successful,位置%s' % article_id # @app.route('/article/test/') # @app.route('/article/<string:test>/') @app.route('/article/<path:test>/') def test_article(test): return 'test_article %s' % test @app.route('/u/<uuid:user_id>/') def user_detail(user_id): return '用戶個人中心頁面:%s' % user_id # /blog/<id>/ # /user/<id>/ @app.route('/<any(blog,user):url_path>/<id>/') def detail(url_path,id): if url_path == 'blog': return '博客詳情:%s' % id else: return '用戶詳情:%s' % id # 通過問好的形式傳遞參數 @app.route('/d/') def d(): wd = request.args.get('wd') ie = request.args.get('ie') print(wd,id,end='') return '查詢字符串參數:%s %s' % (wd,ie) # import uuid # print(uuid.uuid4()) if __name__ == '__main__': app.run(debug=True) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看