{"id":205072,"date":"2025-05-29T15:51:00","date_gmt":"2025-05-29T07:51:00","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205072\/"},"modified":"2025-05-29T15:51:00","modified_gmt":"2025-05-29T07:51:00","slug":"flask-%e4%b8%ad%e8%ae%bf%e9%97%ae%e4%b8%8d%e5%88%b0%e8%a1%a8%e5%8d%95%e6%95%b0%e6%8d%ae%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205072\/","title":{"rendered":"Flask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Flask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aFlask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173228332267408bba17d71.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5728 flask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5982\u56fe\u6240\u793a\uff0c\u5728 flask \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5c1d\u8bd5\u901a\u8fc7 request.form.get() \u83b7\u53d6\u8868\u5355\u6570\u636e\u5374\u5931\u8d25\u4e86\u3002\u8fd9\u662f\u56e0\u4e3a flask \u6839\u636e web \u89c4\u8303\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u6e90\u6765\u5b58\u50a8\u8868\u5355\u6570\u636e\u548c json \u6570\u636e\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u8bbf\u95ee\u8868\u5355\u6570\u636e\uff0c\u9700\u8981\u4f7f\u7528 request.post.get()\uff0c\u5b83\u4e13\u95e8\u7528\u4e8e\u83b7\u53d6\u8868\u5355\u63d0\u4ea4\u7684\u6570\u636e\u3002\u50cf request.form.get() \u8fd9\u6837\u7528\u4e8e\u5904\u7406 json \u6570\u636e\u7684\u65b9\u6cd5\u65e0\u6cd5\u8bbf\u95ee\u8868\u5355\u6570\u636e\u3002<\/p>\n<p><strong>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre>from flask import Flask, request\n\napp = Flask(__name__)\n\n@app.route('\/', methods=['POST'])\ndef index():\n    student_id = request.POST.get('student_id')\n    # \u5176\u4ed6\u4ee3\u7801...<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>request.post \u662f\u4e00\u4e2a\u7c7b\u4f3c\u5b57\u5178\u7684\u5bf9\u8c61\uff0c\u5b83\u5b58\u50a8\u8868\u5355\u6570\u636e\u3002<\/li>\n<li>\u786e\u4fdd\u8868\u5355\u4e2d\u5b57\u6bb5\u7684\u540d\u79f0\u4e0e get() \u65b9\u6cd5\u4e2d\u6307\u5b9a\u7684\u540d\u79f0\u5339\u914d\u3002<\/li>\n<\/ul>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aFlask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flask \u4e2d\u8bbf\u95ee\u4e0d\u5230\u8868\u5355\u6570\u636e\u7684&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205072","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205072"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205072\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}