{"id":6375,"date":"2021-04-06T00:14:00","date_gmt":"2021-04-05T16:14:00","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6375"},"modified":"2022-03-16T14:35:25","modified_gmt":"2022-03-16T06:35:25","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-05-%e7%af%87-%ef%bd%9c-%e8%93%9d%e5%9b%be%e7%9a%84","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6375","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 05 \u7bc7 \uff5c \u84dd\u56fe\u7684\u6784\u5efa\u4f7f\u7528"},"content":{"rendered":"\n<p>\u6211\u4eec\u77e5\u9053\uff0c\u9879\u76ee\u4ee3\u7801\u7684\u7ed3\u6784\u8d8a\u6e05\u6670\uff0c\u6a21\u5757\u5316\u7ba1\u7406\u8d8a\u597d\uff0c\u5bf9\u6211\u4eec\u4ee5\u540e\u7684\u6269\u5c55\u548c\u4f18\u5316\u8d77\u5230\u5f88\u5927\u7684\u4f5c\u7528\u3002\u6240\u4ee5\u9879\u76ee\u4e00\u5f00\u59cb\uff0c\u9879\u76ee\u7684\u7ed3\u6784\u7ec4\u7ec7\u8fd8\u662f\u5f88\u5173\u952e\u7684\uff0c\u6bd4\u5982\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u5982\u4f55\u62c6\u5206\u597d\u5b83\u4eec\uff0c\u4f46\u53c8\u80fd\u4f7f\u7528\u5230\u76f8\u540c\u7684\u8d44\u6e90\uff1f\u53c8\u53ef\u4ee5\u505a\u5230\u76f8\u4e92\u72ec\u7acb\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u300c\u4f4e\u8026\u5408\uff0c\u9ad8\u5185\u805a\u300d\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\u8fd8\u8981\u7ed9\u4f60\u4ecb\u7ecd\u7684\u662f Flask \u7684\u9879\u76ee\u7ed3\u6784\u7ec4\u7ec7\u65b9\u5f0f\uff0c\u90a3\u5c31\u662f Flask \u7684\u84dd\u56fe\u2014\u2014Blueprints\u3002<\/p>\n\n\n\n<h1>\u4ec0\u4e48\u662f Blueprints<\/h1>\n\n\n\n<p>Blueprints \u662f Flask \u63d0\u4f9b\u7684\u4e00\u4e2a\u7c7b\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u521b\u5efa\u84dd\u56fe\uff0c\u7528\u4e8e\u6ce8\u518c\u5728 Flask \u5b9e\u4f8b\u4e2d\uff0c\u4fbf\u4e8e\u5bf9\u81ea\u6a21\u5757\u7684\u7ba1\u7406\uff0c\u6709\u6548\u7684\u63d0\u4f9b\u4e86\u5206\u79bb\uff0c\u5171\u4eab\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 Flask \u521b\u5efa\u5b9e\u4f8b APP \u6765\u76f4\u63a5\u64cd\u4f5c\u5404\u79cd\u8bf7\u6c42\uff0c\u4f46\u5982\u679c\u9879\u76ee\u7684\u529f\u80fd\u6bd4\u8f83\u591a\u529f\u80fd\uff0c\u6211\u4eec\u9700\u8981\u5f52\u7c7b\u597d\u5b83\u4eec\uff0c\u6bd4\u5982\u4f60\u7684\u9879\u76ee\u6709\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\uff0c\u4e5f\u6709\u524d\u7aef\u4f7f\u7528\u7684\u9875\u9762\uff0c\u90a3\u4e48\u5c31\u8981\u6211\u4eec\u53ef\u4ee5\u5206\u522b\u4e3a\u4ed6\u4eec\u521b\u5efa\u4e00\u4e2a\u84dd\u56fe\uff0c\u524d\u7aef\u6709\u524d\u7aef\u7684\u64cd\u4f5c\u65b9\u5f0f\u548c\u6837\u5f0f\uff0c\u540e\u53f0\u7ba1\u7406\u6709\u540e\u53f0\u7684\u7edf\u4e00\u64cd\u4f5c\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u505a\u5230\u5177\u4f53\u6bcf\u4e2a\u84dd\u56fe\u5f97\u5230\u7edf\u4e00\u7ba1\u7406\u64cd\u4f5c\uff0c\u6211\u4eec\u7684\u7a0b\u5e8f\u5c31\u4f1a\u5f88\u6e05\u6670\u3002<\/p>\n\n\n\n<h1>\u84dd\u56fe\u7684\u4f7f\u7528<\/h1>\n\n\n\n<h2>\u84dd\u56fe\u7684\u521b\u5efa<\/h2>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u9879\u76ee\u6587\u4ef6\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u84dd\u56fe package\uff0c\u7528\u5b83\u6765\u7ba1\u7406\u4e0d\u540c\u7684\u6a21\u5757\uff0c\u50cf\u8fd9\u6837\u8fd9\u6837\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>blueprints<br>  \u251c\u2500\u2500 __init__.py<br>  \u251c\u2500\u2500 admin.py<br>  \u251c\u2500\u2500 auth.py<br>  \u2514\u2500\u2500 home.py<\/p><\/blockquote>\n\n\n\n<p>\u5176\u4e2d\uff0cadmin \u662f\u540e\u7aef\u7684\u84dd\u56fe\u6a21\u5757\uff0cauth \u662f\u7528\u6237\u8ba4\u8bc1\u7684\u84dd\u56fe\u6a21\u5757\uff0chome \u662f\u524d\u7aef\u7684\u84dd\u56fe\u6a21\u5757\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u5206\u522b\u5728\u91cc\u9762\u505a\u76f8\u5173\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u4e00\u4e2a\u5173\u4e8e admin \u7684\u84dd\u56fe\u4f60\u53ef\u4ee5\u8fd9\u6837\u521b\u5efa\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>admin<br>\u251c\u2500\u2500 __init__.py<br>\u251c\u2500\u2500 views.py<br>\u251c\u2500\u2500 templates<br>\u2514\u2500\u2500 form.py<\/p><\/blockquote>\n\n\n\n<p>\u90a3\u8fd9\u91cc\u9762\u7684\u64cd\u4f5c\u4e5f\u597d\uff0c\u6837\u5f0f\u4e5f\u597d\uff0c\u90fd\u662f\u53ef\u4ee5\u7edf\u4e00\u5230 admin \u7684\uff0c\u4e5f\u53ef\u4ee5\u548c\u5176\u4ed6\u6a21\u5757\u72ec\u7acb\u5f00\u6765\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u84dd\u56fe\u600e\u4e48\u5199\u5462\uff1f\u6211\u4eec\u4ee5\u300c\u524d\u7aef\u84dd\u56fe\u300d\u6a21\u5757 home \u4e3a\u4f8b\uff0c\u5728 home.py \u4e2d\u5b9a\u4e49\u6a21\u5757\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 Blueprint\n\nhome_bp = Blueprint('home', __name__)\n\n@home_bp.route('\/index')\ndef index():\n    return '\u8fd9\u662f\u9996\u9875'\n  \n@home_bp.route('\/hi')\ndef hi():\n    return '\u4f60\u597d\u554a\u554a\uff01\uff01'\n<\/pre><\/div>\n\n\n\n<p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86\u84dd\u56fe\uff0c\u901a\u8fc7\u5b83\u521b\u5efa\u4e86 home_bp \u5b9e\u4f8b\uff0c\u5176\u4e2d\u4f20\u5165\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u84dd\u56fe\u7684\u540d\u79f0\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f<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%3D6375\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u4f60\u751a\u81f3\u53ef\u4ee5\u8ba9\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u90fd\u72ec\u7acb\u4e8e\u5177\u4f53\u7684\u84dd\u56fe\u4e0b\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f60\u53ef\u4ee5\u5728\u84dd\u56fe\u5305\u4e0b\u521b\u5efa\u5b50\u5305\uff0c\u5728\u5b50\u5305\u4e2d\u7edf\u4e00\u7ba1\u7406\u5404\u4e2a\u84dd\u56fe\u7684\u8d44\u6e90\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u7684\u76ee\u5f55\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>blueprints<br>  \u251c\u2500\u2500 __init__.py<br>  \u251c\u2500\u2500 admin.py<br>  \u251c\u2500\u2500 auth.py<br>  \u2514\u2500\u2500 home.py<\/p><\/blockquote>\n\n\n\n<p>\u53ef\u4ee5\u53d8\u6210\u8fd9\u6837\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>.<br>\u251c\u2500\u2500 __init__.py<br>\u251c\u2500\u2500 admin.py<br>\u251c\u2500\u2500 auth.py<br>\u2514\u2500\u2500 home<br> &nbsp; &nbsp;\u251c\u2500\u2500 __init__.py<br> &nbsp; &nbsp;\u251c\u2500\u2500 home.py<br> &nbsp; &nbsp;\u251c\u2500\u2500 static<br> &nbsp; &nbsp;\u2502&nbsp;&nbsp; \u2514\u2500\u2500 home.css<br> &nbsp; &nbsp;\u2514\u2500\u2500 templates<br> &nbsp; &nbsp; &nbsp; &nbsp;\u2514\u2500\u2500 home.html<\/p><\/blockquote>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u65f6\u5019\u4f60\u60f3\u8981\u5f15\u7528\u8fd9\u4e9b\u8d44\u6e90\uff0c\u53ef\u4ee5\u5728\u521b\u5efa\u84dd\u56fe\u7684\u65f6\u5019\u4f1a\u9ed8\u8ba4\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;}\">home_dp = Blueprint('home', __name__, template_folder='tempaltes', static_folder='static')<\/pre><\/div>\n\n\n\n<p>OK\uff0c\u4ee5\u4e0a\u5c31\u662f Flask \u84dd\u56fe\u4e2d\u7684\u5e38\u7528\u64cd\u4f5c\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u4f1a\u4f7f\u7528\u5230\u5b83\uff0c\u6211\u4eec\u4e0b\u4e00\u7bc7\u518d\u89c1\uff0cpeace\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u77e5\u9053\uff0c\u9879\u76ee\u4ee3\u7801\u7684\u7ed3\u6784\u8d8a\u6e05\u6670\uff0c\u6a21\u5757\u5316\u7ba1\u7406\u8d8a\u597d\uff0c\u5bf9\u6211\u4eec\u4ee5\u540e\u7684\u6269\u5c55\u548c\u4f18\u5316\u8d77\u5230\u5f88\u5927\u7684\u4f5c\u7528\u3002\u6240\u4ee5\u9879\u76ee\u4e00\u5f00\u59cb\uff0c\u9879\u76ee\u7684\u7ed3\u6784\u7ec4\u7ec7\u8fd8\u662f\u5f88\u5173\u952e\u7684\uff0c\u6bd4\u5982\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u5982\u4f55\u62c6\u5206\u597d\u5b83\u4eec\uff0c\u4f46\u53c8\u80fd\u4f7f\u7528\u5230\u76f8\u540c\u7684\u8d44\u6e90\uff1f\u53c8\u53ef\u4ee5\u505a\u5230\u76f8\u4e92\u72ec\u7acb\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u300c\u4f4e\u8026\u5408\uff0c\u9ad8\u5185\u805a\u300d\u3002 \u4eca\u5929\u8fd8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6379,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[570,573,571,569,572,574,575],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6375"}],"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=6375"}],"version-history":[{"count":4,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6375\/revisions"}],"predecessor-version":[{"id":6953,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6375\/revisions\/6953"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6379"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}