{"id":284,"date":"2021-12-19T14:58:06","date_gmt":"2021-12-19T06:58:06","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=284"},"modified":"2022-02-06T12:37:29","modified_gmt":"2022-02-06T04:37:29","slug":"kai-shiflask","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=284","title":{"rendered":"\u5f00\u59cbflask001"},"content":{"rendered":"<h2><a id=\"flask%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>flask\u865a\u62df\u73af\u5883<\/h2>\n<p>\u6839\u636eflask\u5b98\u7f51\u4ecb\u7ecd\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u5305\u62ec\u5f00\u53d1\u4e0e\u751f\u4ea7\u73af\u5883\u3002<\/p>\n<p>\u56e0\u4e3a\u968f\u7740Python\u9879\u76ee\u589e\u591a\uff0c\u5f88\u6709\u53ef\u80fd\u8981\u4e0e\u4e0d\u540c\u7684python\u5e93\u3001\u751a\u81f3\u4e0d\u540c\u7248\u672c\u7684python\u6253\u4ea4\u9053\u3002\u4e00\u4e2a\u9879\u76ee\u7684\u65b0\u7248\u672c\u5e93\u6587\u4ef6\u4e0e\u53e6\u5916\u4e00\u4e2a\u9879\u76ee\u53ef\u80fd\u4e0d\u517c\u5bb9\u3002<\/p>\n<p>\u865a\u62df\u73af\u5883\u72ec\u7acb\u4e8epython\u5e93\uff0c\u4e00\u4e2a\u865a\u62df\u73af\u5883\u5339\u914d\u4e00\u4e2a\u9879\u76ee\u3002\u4e3a\u4e00\u4e2a\u9879\u76ee\u5b89\u88c5\u7684\u5305\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u9879\u76ee\u5305\u6216\u7cfb\u7edf\u5305\u3002<\/p>\n<p>Python\u7ed1\u5b9avenv\u6a21\u5757\u6765\u521b\u9020\u865a\u62df\u73af\u5883\u3002<\/p>\n<h3><a id=\"%E5%88%9B%E5%BB%BA%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u521b\u5efa\u865a\u62df\u73af\u5883<\/h3>\n<p>macOS\/Linux<\/p>\n<pre><code class=\"language-plain_text\">$ mkdir flaskproject\n$ cd flaskproject\n$ python3 -m venv venv\n<\/code><\/pre>\n<h3><a id=\"%E6%BF%80%E6%B4%BB%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/h3>\n<p>macOS\/Linux<\/p>\n<pre><code class=\"language-plain_text\">$  . venv\/bin\/activate\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u8fd9\u4e2a\u201c.\u201d\u548cvenv\u4e4b\u95f4\u8981\u6709\u7a7a\u683c\uff0c\u53c2\u89c1<a href=\"https:\/\/stackoverflow.com\/questions\/45554864\/permission-denied-when-activating-venv\">stackoverflow<\/a>\u7684\u89e3\u91ca\uff1a<\/p>\n<pre><code class=\"language-plain_text\">. venv\/bin\/activate\n<\/code><\/pre>\n<p>or<\/p>\n<pre><code class=\"language-plain_text\">source venv\/bin\/activate\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/12\/16399267612138.jpg\" alt=\"\" \/><\/p>\n<h3><a id=\"%E4%BD%BF%E7%94%A8%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83%EF%BC%8C%E5%B9%B6%E8%AE%BE%E7%BD%AE%E4%B8%BA%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u5e76\u8bbe\u7f6e\u4e3a\u5f00\u53d1\u73af\u5883<\/h3>\n<p>\u5728venv\u73af\u5883\u4e0b\uff0c\u5982\u679c\u76f4\u63a5\u542f\u52a8flask\u670d\u52a1\uff1a<\/p>\n<pre><code class=\"language-plain_text\">flask run\n<\/code><\/pre>\n<p>\u4f1a\u6709\u5982\u4e0b\u7ea2\u8272\u8b66\u544a\u4fe1\u606f\uff0c\u56e0\u4e3aflask\u9ed8\u8ba4\u5f00\u53d1\u8005\u662f\u751f\u4ea7\u73af\u5883\u4e0b\u5de5\u4f5c\uff0c\u800c\u5f00\u53d1\u73af\u5883\u4e0d\u7a33\u5b9a\uff0c\u6240\u4ee5\u4f1a\u63d0\u793a\u5982\u4e0b\u544a\u8b66\u3002<br \/>\n<img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-20-at-12.00.48-AM.png\" alt=\"Screen Shot 2021-12-20 at 12.00.48 AM\" \/><\/p>\n<p>\u56e0\u6b64\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e<\/p>\n<pre><code class=\"language-plain_text\">(venv) MDMacPro\/Users\/XXXXXXXXXXXX\/flaskr\/flaskproject\/bmi[23:58]export FLASK_ENV=development\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/12\/16399299868944.jpg\" alt=\"\" \/><\/p>\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/104028370\">\u53c2\u8003flask\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/a><\/p>\n<h3><a id=\"%E4%BD%BF%E7%94%A8git-checkout-2a\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f7f\u7528git checkout 2a<\/h3>\n<p>\u4f7f\u7528git checkout 2a \u628a\u5bf9\u5e94project\u7684source code\u590d\u5236\u5230visual studio\u91cc\u9762<\/p>\n<p>\u7531\u4e8e\u5df2\u7ecf\u901a\u8fc7git\u542f\u52a8\u4e86\u76f8\u5173\u7a0b\u5e8f\uff0c\u56e0\u6b64\u4f1a\u5c55\u793a\u5982\u4e0b\u5185\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/01\/16423145720419.jpg\" alt=\"\" \/><\/p>\n<h3><a id=\"%E4%BD%BF%E7%94%A8git-reset-hard\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f7f\u7528git reset &#8211;hard<\/h3>\n<p>\u5982\u679c\u5bf9git\u4e0a\u7684\u6e90\u4ee3\u7801\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528git reset &#8211;hard\u653e\u5f03\u6240\u6709\u4fee\u6539<\/p>\n<pre><code class=\"language-plain_text\">(venv) MDMacPro\/Users\/madapapa\/Study\/madapapa.com\/flaskr\/flaskproject\/flaskygit:(32acca2) \u2717 [12:07]git reset --hard\nHEAD is now at 32acca2 Chapter 2: Dynamic routes (2b)\n(venv) MDMacPro\/Users\/madapapa\/Study\/madapapa.com\/flaskr\/flaskproject\/flaskygit:(32acca2) [12:09]git checkout 3a\nPrevious HEAD position was 32acca2 Chapter 2: Dynamic routes (2b)\nHEAD is now at e020af8 Chapter 3: Templates (3a)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>flask\u865a\u62df\u73af\u5883 \u6839\u636eflask\u5b98\u7f51\u4ecb\u7ecd\uff0c\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u5305\u62ec\u5f00\u53d1\u4e0e\u751f\u4ea7\u73af\u5883\u3002 \u56e0\u4e3a\u968f\u7740Python\u9879\u76ee\u589e\u591a\uff0c\u5f88\u6709\u53ef\u80fd\u8981\u4e0e\u4e0d\u540c\u7684python\u5e93\u3001\u751a\u81f3\u4e0d\u540c\u7248\u672c\u7684python\u6253\u4ea4\u9053\u3002\u4e00\u4e2a\u9879\u76ee\u7684\u65b0\u7248\u672c\u5e93\u6587\u4ef6\u4e0e\u53e6\u5916\u4e00\u4e2a\u9879\u76ee\u53ef\u80fd\u4e0d\u517c\u5bb9\u3002 \u865a\u62df\u73af\u5883\u72ec\u7acb\u4e8epython\u5e93\uff0c\u4e00\u4e2a\u865a\u62df\u73af\u5883\u5339\u914d\u4e00\u4e2a\u9879\u76ee\u3002\u4e3a\u4e00\u4e2a\u9879\u76ee\u5b89\u88c5\u7684\u5305\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u9879\u76ee\u5305\u6216\u7cfb\u7edf\u5305\u3002 Python\u7ed1\u5b9avenv\u6a21\u5757\u6765\u521b\u9020\u865a\u62df\u73af\u5883\u3002 \u521b\u5efa\u865a\u62df\u73af\u5883 macOS\/Linux $ mkdir flaskproject $ cd flaskproject $ python3 -m venv venv \u6fc0\u6d3b\u865a\u62df\u73af\u5883 macOS\/Linux $ . venv\/bin\/activate \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u8fd9\u4e2a\u201c.\u201d\u548cvenv\u4e4b\u95f4\u8981\u6709\u7a7a\u683c\uff0c\u53c2\u89c1stackoverflow\u7684\u89e3\u91ca\uff1a . venv\/bin\/activate or source venv\/bin\/activate \u4f7f\u7528\u865a\u62df\u73af\u5883\uff0c\u5e76\u8bbe\u7f6e\u4e3a\u5f00\u53d1\u73af\u5883 \u5728venv\u73af\u5883\u4e0b\uff0c\u5982\u679c\u76f4\u63a5\u542f\u52a8flask\u670d\u52a1\uff1a flask run \u4f1a\u6709\u5982\u4e0b\u7ea2\u8272\u8b66\u544a\u4fe1\u606f\uff0c\u56e0\u4e3aflask\u9ed8\u8ba4\u5f00\u53d1\u8005\u662f\u751f\u4ea7\u73af\u5883\u4e0b\u5de5\u4f5c\uff0c\u800c\u5f00\u53d1\u73af\u5883\u4e0d\u7a33\u5b9a\uff0c\u6240\u4ee5\u4f1a\u63d0\u793a\u5982\u4e0b\u544a\u8b66\u3002 \u56e0\u6b64\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e (venv) MDMacPro\/Users\/XXXXXXXXXXXX\/flaskr\/flaskproject\/bmi[23:58]export FLASK_ENV=development \u53c2\u8003flask\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf \u4f7f\u7528git checkout 2a \u4f7f\u7528git checkout 2a \u628a\u5bf9\u5e94project\u7684source code\u590d\u5236\u5230visual studio\u91cc\u9762 \u7531\u4e8e\u5df2\u7ecf\u901a\u8fc7git\u542f\u52a8\u4e86\u76f8\u5173\u7a0b\u5e8f\uff0c\u56e0\u6b64\u4f1a\u5c55\u793a\u5982\u4e0b\u5185\u5bb9\u3002 \u4f7f\u7528git reset &#8211;hard \u5982\u679c\u5bf9git\u4e0a\u7684\u6e90\u4ee3\u7801\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528git reset &#8211;hard\u653e\u5f03\u6240\u6709\u4fee\u6539 &hellip; <a href=\"http:\/\/madapapa.com\/wordpress\/?p=284\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u5f00\u59cbflask001<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[5,11],"tags":[],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-linux","category-tech"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284"}],"version-history":[{"count":8,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":312,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions\/312"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}