{"id":186,"date":"2023-02-19T19:36:54","date_gmt":"2023-02-19T11:36:54","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=186"},"modified":"2023-02-19T19:38:31","modified_gmt":"2023-02-19T11:38:31","slug":"python-deploy-http-server-use-virtualenv-to-install-flask-under-windows","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/19\/python-deploy-http-server-use-virtualenv-to-install-flask-under-windows\/","title":{"rendered":"Python\u642d\u5efaHTTP\u670d\u52a1\u5668\uff1aWindows\u4e0b\u4f7f\u7528virtualenv\u5b89\u88c5Flask"},"content":{"rendered":"<h2>Flask\u4ecb\u7ecd<\/h2>\n<p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u5e94\u7528\u6846\u67b6\uff0c\u4f7f\u7528Python\u7f16\u5199\u3002\u57fa\u4e8e WerkzeugWSGI\u5de5\u5177\u7bb1\u548c Jinja2\u6a21\u677f\u5f15\u64ce\u3002Flask\u4f7f\u7528 BSD \u6388\u6743\u3002<br \/>\nFlask\u4e5f\u88ab\u79f0\u4e3a\u201cmicroframework\u201d\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u7b80\u5355\u7684\u6838\u5fc3\uff0c\u7528 extension \u589e\u52a0\u5176\u4ed6\u529f\u80fd\u3002Flask\u6ca1\u6709\u9ed8\u8ba4\u4f7f\u7528\u7684\u6570\u636e\u5e93\u3001\u7a97\u4f53\u9a8c\u8bc1\u5de5\u5177\u3002\u7136\u800c\uff0cFlask\u4fdd\u7559\u4e86\u6269\u589e\u7684\u5f39\u6027\uff0c\u53ef\u4ee5\u7528Flask-extension\u52a0\u5165\u8fd9\u4e9b\u529f\u80fd\uff1aORM\u3001\u7a97\u4f53\u9a8c\u8bc1\u5de5\u5177\u3001\u6587\u4ef6\u4e0a\u4f20\u3001\u5404\u79cd\u5f00\u653e\u5f0f\u8eab\u4efd\u9a8c\u8bc1\u6280\u672f\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>Flask\u5b89\u88c5\u51c6\u5907<\/h2>\n<p>Flask\u5b89\u88c5\u7684\u524d\u63d0\u6761\u4ef6\uff1a<\/p>\n<ol>\n<li>\u5df2\u5b89\u88c5python2.x\u7248\u672c<\/li>\n<li>\u5df2\u5b89\u88c5easy_install<\/li>\n<\/ol>\n<p>\u5728\u5b89\u88c5flask\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5python\u548ceasy_install\uff0ceasy_install\u53ea\u652f\u6301pyhon2.x\u7248\u672c\u4e0d\u652f\u6301python3.x\u7248\u672c\uff0c\u6240\u4ee5\u5728\u5b89\u88c5python\u7684\u65f6\u5019\u6700\u597d\u9009\u62e9python2.x\uff0c\u5982python2.7\u3002<\/p>\n<p>Python\u5b98\u7f51\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/www.python.org\/\">http:\/\/www.python.org\/<\/a><\/p>\n<p>easy_install\u5b98\u65b9\u4e0b\u8f7d\u5730\u5740\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/pypi.python.org\/pypi\/setuptools\">http:\/\/pypi.python.org\/pypi\/setuptools<\/a> <\/p>\n<p>\u53ef\u4ee5\u627e\u5230\u6b63\u786e\u7684easy_install\u7248\u672c\u8fdb\u884c\u4e0b\u8f7d\u5b89\u88c5\u3002win7 32\u4f4d\u53ef\u4ee5\u4e0b\u8f7d\u5b89\u88c5\uff1asetuptools-0.6c11.win32-py2.7.exe\uff0c\u4e0b\u8f7d\u9875\u9762\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/pypi.python.org\/pypi\/setuptools\/0.6c11\">https:\/\/pypi.python.org\/pypi\/setuptools\/0.6c11<\/a><\/p>\n<blockquote>\n<p>\u6ce8\u610f\uff1awin7 64\u4f4d\u5fc5\u987b\u4f7f\u7528<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/peak.telecommunity.com\/dist\/ez_setup.py\">ez_setup.py<\/a>\u8fdb\u884c\u5b89\u88c5\u3002\u65b9\u6cd5\u662f\u4e0b\u8f7dez_setup.py\u540e\uff0c\u5728cmd\u4e0b\u6267\u884c <code>python ez_setup.py<\/code>\uff0c\u5373\u53ef\u81ea\u52a8\u5b89\u88c5setuptools\u3002\u76ee\u524d\u6ca1\u6709\u76f4\u63a5\u7684exe\u5b89\u88c5\u7248\u672c\u3002<\/p>\n<\/blockquote>\n<p>\u5b89\u88c5\u5b8ceasy_install\u540e\uff0c\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u7684PATH\u4e2d\u6dfb\u52a0easy_install\u6240\u5728\u7684\u76ee\u5f55\uff0c\u4f8b\u5982\uff1aC:\\Python27\\Scripts<\/p>\n<h2>\u5f00\u59cb\u5b89\u88c5Flask<\/h2>\n<p>\u5982\u679c\u4f60\u5df2\u7ecf\u628aPython2.7\u548ceast_install\u5168\u90e8\u5b89\u88c5\u5b8c\u6bd5\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5b89\u88c5Flask\u3002<\/p>\n<p>\u9996\u5148\u6253\u5f00\u63a7\u5236\u53f0\uff0c\u8f93\u5165<code>easy_install virtualenv<\/code>\uff0c\u5b89\u88c5 virtualenv\uff0c\u8fd9\u4e2a\u4e3b\u8981\u662f\u7528\u6765\u505a\u89e3\u91ca\u5668\u73af\u5883\u9694\u79bb\u7684\uff0c\u907f\u514d\u540c\u4e00\u673a\u5668\u4e0a\u7684\u591a\u4e2apython\u6216\u8005\u591a\u4e2apython\u7684\u5e93\u4f9d\u8d56<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Python\/\u5b89\u88c5virtualenv.png\" alt=\"\u5b89\u88c5virtualenv\" \/><\/p>\n<p>\u7136\u540e\u914d\u7f6e\u865a\u62df\u73af\u5883<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Python\/\u914d\u7f6e\u865a\u62df\u73af\u5883.png\" alt=\"\u914d\u7f6e\u865a\u62df\u73af\u5883\" \/><\/p>\n<p>\u6b64\u65f6\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u6587\u4ef6\u5939myvir<br \/>\n\u7136\u540ecd\u5230myvir\u76ee\u5f55\u7684Scripts\u4e0b\u8f93\u5165<code>activate.bat<\/code>\uff0c\u8fdb\u5165\u865a\u62df\u73af\u5883\uff0c\u8f93\u5165<code>easy_install Flask<\/code><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Python\/\u5b89\u88c5Flask.png\" alt=\"\u5b89\u88c5Flask\" \/><\/p>\n<h2>Flask\u5b89\u88c5\u6d4b\u8bd5<\/h2>\n<p>\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u6211\u4eec\u6d4b\u8bd5\u4e00\u4e0b\u662f\u5426\u80fd\u6b63\u5e38\u8fd0\u884c<\/p>\n<p>\u5728Scripts\u4e0b\u65b0\u5efa\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u8f93\u5165\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code>from flask import Flask\n\napp=Flask(__name__)\n\n@app.route(&#039;\/&#039;)\n\ndef hello_world():  \n    return &quot;Hello World&quot;\n\nif __name__ == &#039;__main__&#039;:\n    app.run()<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e3ahello.py<\/p>\n<p>\u6700\u540e\u5728\u63a7\u5236\u53f0\u4e0a\u8f93\u5165Python hello.py<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Python\/\u6d4b\u8bd5Flask.png\" alt=\"\u6d4b\u8bd5Flask\" \/><\/p>\n<p>\u7136\u540e\u6253\u5f00\u6d4f\u89c8\u5668\u8f93\u5165127.0.0.1\uff1a5000\uff0c\u5c31\u770b\u5230\u4e86Hello World\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Python\/Flask\u6d4b\u8bd5\u6210\u529f.png\" alt=\"Flask\u6d4b\u8bd5\u6210\u529f\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flask\u4ecb\u7ecd Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u5e94\u7528\u6846\u67b6\uff0c\u4f7f\u7528Python\u7f16\u5199\u3002\u57fa\u4e8e WerkzeugWSGI\u5de5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[80],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-python","tag-flask"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}