{"id":6349,"date":"2021-03-22T22:27:36","date_gmt":"2021-03-22T14:27:36","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6349"},"modified":"2021-03-22T22:28:04","modified_gmt":"2021-03-22T14:28:04","slug":"%e4%bd%bf%e7%94%a8-python-%e4%bb%8e-0-%e5%bc%80%e5%8f%91%e5%b1%9e%e4%ba%8e%e4%bd%a0%e7%9a%84%e4%b8%aa%e4%ba%ba%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f-02-%e7%af%87%ef%bd%9c-%e8%bf%99%ef%bc%8c%e5%b0%b1","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6349","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 02 \u7bc7\uff5c \u8fd9\uff0c\u5c31\u662f Flask \u7684\u8bf7\u6c42\u4ea4\u4e92\u64cd\u4f5c"},"content":{"rendered":"\n<p>\u5728<a href=\"https:\/\/vip.fxxkpython.com\/?p=6341\">\u4e0a\u4e00\u7bc7<\/a>\u4e2d\uff0c\u6211\u4eec\u4ece\u9879\u76ee\u865a\u62df\u73af\u5883\u7684\u642d\u5efa\uff0c\u5230\u670d\u52a1\u7684\u542f\u52a8\u90fd\u4ecb\u7ecd\u4e86\uff0c\u5e76\u4e14\u54b1\u4eec\u4e5f\u5efa\u7acb\u4e86\u4e00\u4e2a py \u6587\u4ef6\uff0c\u628a Flask \u6700\u57fa\u672c\u7684\u4f7f\u7528\u65b9\u5f0f\u7ed9\u73a9\u4e86\u4e00\u4e0b\uff0c\u8bf7\u8fdb\u5165\u4f60\u7684\u9879\u76ee\uff0c\u628a fxxkpython.py \u6587\u4ef6\u6253\u5f00:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from flask import Flask\napp = Flask(__name__)\n\n@app.route('\/')\ndef hello():\n    return 'fxxkpython!!'\n\n@app.route('\/abc')\ndef abc():\n    return '&lt;h1 style=&quot;background-color:#CCBBCC;&quot;&gt;\u5e05\u5e05\u7684abc&lt;\/h1&gt;<\/pre><\/div>\n\n\n\n<p>\u54b1\u4eec\u63a5\u4e0b\u6765\u7ee7\u7eed\u73a9\u2014\u2014Flask \u5e38\u7528\u7684\u8bf7\u6c42\u4ea4\u4e92\u64cd\u4f5c\uff01<\/p>\n\n\n\n<h2>\u63a5\u6536\u5ba2\u6237\u7aef\u4f20\u6765\u7684\u53c2\u6570<\/h2>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 &lt;> \u6765\u63a5\u6536 URL \u4f20\u6765\u7684\u53c2\u6570\uff0c\u6bd4\u5982\u4f60\u8981\u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u6765\u7684 name\uff0c\u90a3\u4e48\u4f60\u5728\u8def\u7531\u4e2d\u5c31\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from flask import Flask\napp = Flask(__name__)\n\n@app.route('\/&lt;name&gt;')\ndef hello(name):\n    return f'fxxk, {name}'<\/pre><\/div>\n\n\n\n<p>\u8fd9\u65f6\u5019\u7528\u6237\u5728\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684 URL \u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><a href=\"http:\/\/127.0.0.1:5000\/hansomeb\">http:\/\/127.0.0.1:5000\/hansomeb<\/a><\/p><\/blockquote>\n\n\n\n<p>\u90a3\u4e48\u8fd4\u56de\u7684\u7ed3\u679c\u5c31\u662f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>fxxk, hansomeb<\/p><\/blockquote>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6211\u4eec\u5728\u8def\u7531\u4e2d\u5b9a\u4e49\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u8ba9 URL \u4ee5\u4e00\u5b9a\u7684\u89c4\u5219\u8fdb\u884c\u8bf7\u6c42\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u76f8\u5e94\u7684\u6570\u636e\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u548c\u524d\u7aef\u505a\u4ea4\u4e92\u4e86\u3002<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c Flask \u83b7\u53d6\u7684\u53d8\u91cf\u7c7b\u578b\u662f String\uff0c\u50cf\u6211\u4eec\u521a\u521a\u7684 name\uff0c\u5b9e\u9645\u4e0a\u662f&lt;string:name> \uff0c\u9664\u4e86 string \u7c7b\u578b\uff0cFlask \u8fd8\u53ef\u4ee5\u63a5\u6536\u4ee5\u4e0b\u7684\u7c7b\u578b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><br>&lt;int:xxx&gt; \u6574\u6570\u7c7b\u578b<\/p><p>&lt;float:xxx&gt; \u6d6e\u70b9\u7c7b\u578b<\/p><p>&lt;path:xxx&gt; \u5305\u542b\u4e0b\u5212\u7ebf\u7684\u5b57\u7b26\u4e32\u8def\u5f84\u7c7b\u578b<\/p><p>&lt;uuid:xxx&gt; UUID \u7c7b\u578b<\/p><\/blockquote>\n\n\n\n<p>\u6bd4\u5982\u4f60\u5b9a\u4e49\u8fd9\u6837\u7684\u8def\u7531\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"># \u63a5\u6536\u8def\u5f84\u7c7b\u578b\n@app.route('\/&lt;path:subpath&gt;')\ndef subpath(subpath):\n    return f'\u5f97\u5230\u8def\u5f84\uff1a{subpath}'\n                      <\/pre><\/div>\n\n\n\n<p>\u90a3\u4e48\u5f53\u4f60\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee <a href=\"http:\/\/127.0.0.1:5000\/111\/222\/33\/4\">http:\/\/127.0.0.1:5000\/111\/222\/33\/4<\/a> \uff0c\u7ed3\u679c\u5c31\u662f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u5f97\u5230\u8def\u5f84\uff1a111\/222\/33\/4<\/p><\/blockquote>\n\n\n\n<p>\u7c7b\u4f3c\u7684\uff0c UUID\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"># \u63a5\u6536 UUID \u7c7b\u578b\n@app.route('\/uuid\/&lt;uuid:my_uuid&gt;')\ndef uuid(my_uuid):\n    return f'\u5f97\u5230uuid\uff1a{my_uuid}'<\/pre><\/div>\n\n\n\n<p>\u90a3\u4e48\u5f53\u4f60\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee <a href=\"http:\/\/127.0.0.1:5000\/uuid\/dee17400-8b02-11eb-8dcd-0242ac130003\">http:\/\/127.0.0.1:5000\/uuid\/dee17400-8b02-11eb-8dcd-0242ac130003<\/a> \uff0c\u7ed3\u679c\u5c31\u662f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u5f97\u5230uuid\uff1adee17400-8b02-11eb-8dcd-0242ac130003<\/p><\/blockquote>\n\n\n\n<h2>HTTP \u7684\u8bf7\u6c42\u65b9\u6cd5<\/h2>\n\n\n\n<p>HTTP \u6709\u591a\u79cd\u8bf7\u6c42\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8def\u7531\u4e2d\u5b9a\u4e49\uff0c\u4ec0\u4e48\u65b9\u6cd5\u63a5\u6536\u4ec0\u4e48\u6837\u7684\u8bf7\u6c42\uff0c\u53ef\u4ee5\u4f7f\u7528 methods \u6765\u6307\u5b9a\uff0c\u6bd4\u5982\u50cf\u4e00\u4e9b\u8868\u5355\u7684\u8bf7\u6c42\uff0c\u6211\u4eec\u9700\u8981\u6307\u5b9a POST \u8bf7\u6c42\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u50cf\u8fd9\u6837\u5b9a\u4e49\uff1a<div style=\"text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;\">\u672c\u6587\u9690\u85cf\u5185\u5bb9 <a href=\"https:\/\/vip.fxxkpython.com\/wp-login.php?redirect_to=https%3A%2F%2Fvip.fxxkpython.com%2F%3Fp%3D6349\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u6211\u4eec\u901a\u8fc7 render_template \u5c06\u53d8\u91cf name \u4f20\u9012\u7ed9 fxxk.html\uff0c\u8fd9\u6837\u8fd0\u884c\u8d77\u6765\u7684\u5c31\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"550\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1-1024x550.png\" alt=\"\" class=\"wp-image-6351\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1-1024x550.png 1024w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1-300x161.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1-768x412.png 768w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1-769x413.png 769w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-22-\u4e0b\u53489.48.10-1.png 1088w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>ok\uff0c\u672c\u7bc7\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u4f60\u8d76\u7d27\u8bd5\u8bd5\u5427\uff0c\u4e0b\u4e00\u7bc7\u5c06\u4f1a\u7ed9\u4f60\u7ee7\u7eed\u4ecb\u7ecd\uff0c\u5173\u4e8e Flask \u7684\u54cd\u5e94\u64cd\u4f5c\uff0c\u6bd4\u5982\u5982\u4f55\u5199 API\uff0c\u91cd\u5b9a\u5411\uff0c404\uff0c\u4f1a\u8bdd\u7b49\u64cd\u4f5c\uff0c\u6211\u4eec\u4e0b\u56de\u89c1\uff0cpeace\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e0a\u4e00\u7bc7\u4e2d\uff0c\u6211\u4eec\u4ece\u9879\u76ee\u865a\u62df\u73af\u5883\u7684\u642d\u5efa\uff0c\u5230\u670d\u52a1\u7684\u542f\u52a8\u90fd\u4ecb\u7ecd\u4e86\uff0c\u5e76\u4e14\u54b1\u4eec\u4e5f\u5efa\u7acb\u4e86\u4e00\u4e2a py \u6587\u4ef6\uff0c\u628a Flask \u6700\u57fa\u672c\u7684\u4f7f\u7528\u65b9\u5f0f\u7ed9\u73a9\u4e86\u4e00\u4e0b\uff0c\u8bf7\u8fdb\u5165\u4f60\u7684\u9879\u76ee\uff0c\u628a fxxkpython.py \u6587\u4ef6\u6253\u5f00: \u54b1\u4eec\u63a5\u4e0b\u6765\u7ee7\u7eed\u73a9\u2014\u2014Flask \u5e38\u7528\u7684\u8bf7\u6c42\u4ea4\u4e92\u64cd\u4f5c\uff01&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6351,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[549,551,553,69,550,552],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6349"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6349"}],"version-history":[{"count":1,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6349\/revisions"}],"predecessor-version":[{"id":6352,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6349\/revisions\/6352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6351"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}