{"id":57816,"date":"2025-08-15T20:20:13","date_gmt":"2025-08-15T12:20:13","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/57816.html"},"modified":"2025-08-15T20:20:13","modified_gmt":"2025-08-15T12:20:13","slug":"flask%e9%94%99%e8%af%af%e5%a4%84%e7%90%86%e4%b8%8e%e4%bc%9a%e8%af%9d%e6%8a%80%e6%9c%af%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/57816.html","title":{"rendered":"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3"},"content":{"rendered":"<h2>flask\u5165\u95e8day03<\/h2>\n<h3>\u9519\u8bef\u5904\u7406<\/h3>\n<p>1.abort\u51fd\u6570&#xff1a;\u653e\u5f03\u8bf7\u6c42\u5e76\u8fd4\u56de\u9519\u8bef\u4ee3\u7801<\/p>\n<p>\u8be6\u7ec6\u72b6\u6001\u7801<\/p>\n<p>from flask import Flask,abort,render_template<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0return &#039;\u6211\u662f\u9996\u9875&#039;<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/error&#039;)<br \/>\ndef error():<br \/>\n \u00a0 \u00a0abort(404)<br \/>\n \u00a0 \u00a0return &#039;\u6ca1\u6709\u627e\u5230\u9875\u9762&#039;<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122002-689f25f283fa8.png\" \/><\/p>\n<p>\u4f46\u662f\u4ee5\u4e0a\u7684\u65b9\u6cd5&#xff0c;\u9875\u9762\u4f1a\u76f4\u63a5\u663e\u793a\u6210\u8fd9\u6837\u7684&#xff0c;\u7528\u6237\u53ef\u80fd\u4e0d\u662f\u5f88\u806a\u660e&#xff0c;\u4f1a\u4ee5\u4e3a\u662f\u7f51\u7ad9\u7684\u95ee\u9898&#xff0c;\u4e3a\u4e86\u89e3\u51b3\u4ee5\u4e0a\u7684\u5185\u5bb9&#xff0c;\u8bf7\u770b\u4e0b\u9762\u7684\u8bb2\u89e3<\/p>\n<h3>\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u89c6\u56fe<\/h3>\n<ul>\n<li>\n<p>\u4f7f\u7528 errorhandler \u88c5\u9970\u5668&#xff0c;\u63a5\u53d7\u4e00\u4e2ahttp\u72b6\u6001\u7801\u4e3a\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u89c6\u56fe\u4e0d\u5355\u5355\u4f5c\u7528\u4e8eabort\u51fd\u6570\u629b\u51fa\u7684\u9519\u8bef&#xff0c;\u4e5f\u4f5c\u7528\u4e8e\u6574\u4e2aFlask\u5e94\u7528\u5bf9\u5e94\u9519\u8bef\u7801\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u89c6\u56fe\u63a5\u6536\u4e00\u4e2a\u53c2\u6570&#xff0c;\u662fFlask\u5e94\u7528\u7684\u9ed8\u8ba4\u62a5\u9519\u4fe1\u606f<\/p>\n<\/li>\n<\/ul>\n<p>from flask import Flask,render_template<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0return &#039;\u6211\u662f\u9996\u9875&#039;<br \/>\n\u200b<br \/>\n&#064;app.errorhandler(404)<br \/>\ndef error(e):# \u51fd\u6570\u91cc\u9762\u5fc5\u987b\u8981\u4f20\u5165\u4e00\u4e2a\u53c2\u6570<br \/>\n \u00a0 \u00a0# \u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u89c6\u56fe\u51fd\u6570<br \/>\n \u00a0 \u00a0# \u4f7f\u7528 errorhandler \u88c5\u9970\u5668&#xff0c;\u63a5\u53d7\u4e00\u4e2ahttp\u72b6\u6001\u7801\u4e3a\u53c2\u6570\u3002<br \/>\n \u00a0 \u00a0# \u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u89c6\u56fe\u4e0d\u5355\u5355\u4f5c\u7528\u4e8eabort\u51fd\u6570\u629b\u51fa\u7684\u9519\u8bef&#xff0c;\u4e5f\u4f5c\u7528\u4e8e\u6574\u4e2aFlask\u5e94\u7528\u5bf9\u5e94\u9519\u8bef\u7801\u3002<br \/>\n \u00a0 \u00a0# \u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u89c6\u56fe\u63a5\u6536\u4e00\u4e2a\u53c2\u6570&#xff0c;\u662fFlask\u5e94\u7528\u7684\u9ed8\u8ba4\u62a5\u9519\u4fe1\u606f<br \/>\n \u00a0 \u00a0# \u53ef\u4ee5\u6709\u591a\u4e2aerrorhandler\u5904\u7406\u4e0d\u540c\u7684\u9519\u8bef<br \/>\n \u00a0 \u00a0return render_template(&#039;error.html&#039;)<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p>\u53ef\u4ee5\u5236\u4f5c\u4e00\u4e2a\u9519\u8bef\u663e\u793a\u9875\u9762&#xff0c;\u5f53\u7528\u6237\u627e\u4e0d\u5230\u9875\u9762\u7684\u65f6\u5019&#xff0c;\u8ba9\u4ed6\u53ef\u4ee5\u8df3\u8f6c\u56de\u9996\u9875<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html lang&#061;&#034;zh-CN&#034;&gt;<br \/>\n&lt;head&gt;<br \/>\n \u00a0 \u00a0&lt;meta charset&#061;&#034;UTF-8&#034;&gt;<br \/>\n \u00a0 \u00a0&lt;meta name&#061;&#034;viewport&#034; content&#061;&#034;width&#061;device-width, initial-scale&#061;1.0&#034;&gt;<br \/>\n \u00a0 \u00a0&lt;title&gt;\u9875\u9762\u672a\u627e\u5230 &#8211; 404\u9519\u8bef&lt;\/title&gt;<br \/>\n \u00a0 \u00a0&lt;style&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0* {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin: 0;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 0;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0box-sizing: border-box;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-family: &#039;Segoe UI&#039;, &#039;Microsoft YaHei&#039;, sans-serif;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0body {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0min-height: 100vh;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0display: flex;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0justify-content: center;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0align-items: center;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0background: #f8f9fa;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 20px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #333;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0line-height: 1.6;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .container {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0text-align: center;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0max-width: 500px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0width: 100%;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 40px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0background: white;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0border-radius: 12px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .error-code {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 7rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-weight: 800;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-bottom: 15px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0line-height: 1;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0h1 {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 2rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-bottom: 20px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #444;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0p {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1.1rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-bottom: 30px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #666;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .home-btn {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0display: inline-block;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 14px 40px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0background: #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: white;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0text-decoration: none;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0border-radius: 6px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-weight: 600;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1.1rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0transition: all 0.2s ease;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0border: 2px solid #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-top: 20px;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .home-btn:hover {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0background: white;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .error-icon {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 6rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-bottom: 20px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0opacity: 0.8;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .links {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0display: flex;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0justify-content: center;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0gap: 25px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0margin-top: 40px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0flex-wrap: wrap;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .links a {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0color: #6e8efb;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0text-decoration: none;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-weight: 500;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0  .links a:hover {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0text-decoration: underline;<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&#064;media (max-width: 768px) {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  .container {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 30px 25px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  .error-code {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 5.5rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0h1 {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1.7rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0p {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&#064;media (max-width: 480px) {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  .error-code {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 4.5rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0h1 {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1.5rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  .home-btn {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0padding: 12px 30px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0font-size: 1rem;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  .links {<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0gap: 15px;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0 \u00a0  }<br \/>\n \u00a0 \u00a0&lt;\/style&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n \u00a0 \u00a0&lt;div class&#061;&#034;container&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;div class&#061;&#034;error-icon&#034;&gt;\u274c&lt;\/div&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;div class&#061;&#034;error-code&#034;&gt;404&lt;\/div&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;h1&gt;\u9875\u9762\u672a\u627e\u5230&lt;\/h1&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;p&gt;\u60a8\u8bbf\u95ee\u7684\u9875\u9762\u53ef\u80fd\u5df2\u88ab\u79fb\u9664\u6216\u6682\u65f6\u4e0d\u53ef\u7528\u3002\u8bf7\u68c0\u67e5URL\u662f\u5426\u6b63\u786e&#xff0c;\u6216\u8fd4\u56de\u9996\u9875\u7ee7\u7eed\u6d4f\u89c8\u3002&lt;\/p&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;a href&#061;&#034;\/&#034; class&#061;&#034;home-btn&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u8fd4\u56de\u9996\u9875<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/a&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;div class&#061;&#034;links&#034;&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;a href&#061;&#034;#&#034;&gt;\u8054\u7cfb\u6211\u4eec&lt;\/a&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;a href&#061;&#034;#&#034;&gt;\u5e2e\u52a9\u4e2d\u5fc3&lt;\/a&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;a href&#061;&#034;#&#034;&gt;\u7f51\u7ad9\u5730\u56fe&lt;\/a&gt;<br \/>\n \u00a0 \u00a0 \u00a0 \u00a0&lt;\/div&gt;<br \/>\n \u00a0 \u00a0&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt; <\/p>\n<h3>\u54cd\u5e94\u6570\u636e<\/h3>\n<h4>\u8ba4\u8bc6\u54cd\u5e94<\/h4>\n<p>\u89c6\u56fe\u51fd\u6570\u7684 return \u503c\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u4e00\u4e2a\u54cd\u5e94\u5bf9\u8c61\u3002\u5982\u679c\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c; \u5b83\u88ab\u8f6c\u6362\u4e3a\u8be5\u5b57\u7b26\u4e32\u4e3a\u4e3b\u4f53\u7684\u3001\u72b6\u6001\u7801\u4e3a 200 \u7684 &#xff0c;MIME \u7c7b\u578b\u662f text\/html \u7684\u54cd\u5e94\u5bf9\u8c61\u3002<\/p>\n<p>Flask \u628a\u8fd4\u56de\u503c\u8f6c\u6362\u4e3a\u54cd\u5e94\u5bf9\u8c61\u7684\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u54cd\u5e94\u5bf9\u8c61\u4f1a\u7528\u5b57\u7b26\u4e32\u6570\u636e\u548c\u9ed8\u8ba4\u53c2\u6570\u521b\u5efa\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5143\u7ec4&#xff0c;\u4e14\u5143\u7ec4\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u63d0\u4f9b\u989d\u5916\u7684\u4fe1\u606f\u3002\u8fd9\u6837\u7684\u5143\u7ec4\u5fc5\u987b\u662f (response,status, headers) \u7684\u5f62\u5f0f&#xff0c;\u4e14\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u5143\u7d20\u3002 status \u503c\u4f1a\u8986\u76d6\u72b6\u6001\u4ee3\u7801&#xff0c; headers \u53ef\u4ee5\u662f\u4e00\u4e2a\u5217\u8868\u5143\u7d20\u662f\u5143\u7956\u6216\u5b57\u5178&#xff0c;\u4f5c\u4e3a\u989d\u5916\u7684\u6d88\u606f\u6807\u5934\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u54cd\u5e94\u5bf9\u8c61&#xff0c;\u5b83\u4f1a\u4ece\u89c6\u56fe\u76f4\u63a5\u8fd4\u56de\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6211\u4eec\u4e4b\u524d\u90fd\u662f\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32&#xff0c;Flask\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u521b\u5efaresponse\u5bf9\u8c61\u3002<\/p>\n<p>\u54cd\u5e94\u5185\u5bb9\u53ef\u4ee5\u662f\u5217\u8868\u5957\u5143\u7ec4\u6765\u6784\u5efa<\/p>\n<p>from flask import Flask<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0return &#039;\u6211\u662f\u9996\u9875&#039;,200,[(&#039;subject&#039;,&#039;python&#039;),( &#039;chapter&#039;, 2)]<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p>\u54cd\u5e94\u4e5f\u53ef\u4ee5\u662f\u5b57\u5178\u7684\u5f62\u5f0f\u6784\u5efa<\/p>\n<p>from flask import Flask<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0# [(&#039;subject&#039;,&#039;python&#039;),( &#039;chapter&#039;, 2)]<br \/>\n \u00a0 \u00a0return &#039;\u6211\u662f\u9996\u9875&#039;,200,{&#039;subject&#039;:&#039;python&#039;,&#039;chapter&#039;:&#039;2&#039;}<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<h4>\u67e5\u770b\u8fd4\u56de\u7684\u54cd\u5e94\u7684\u5185\u5bb9<\/h4>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122004-689f25f43914b.png\" \/><\/p>\n<h4>\u54cd\u5e94\u5bf9\u8c61<\/h4>\n<p>make_response \u521b\u5efa\u54cd\u5e94\u5bf9\u8c61<\/p>\n<p>&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0response &#061; make_response(&#039;hello world&#039;)<br \/>\n \u00a0 \u00a0# \u65b9\u5f0f1<br \/>\n \u00a0 \u00a0# response.status_code &#061; 200<br \/>\n \u00a0 \u00a0# \u65b9\u5f0f2<br \/>\n \u00a0 \u00a0response.status &#061; 200<br \/>\n \u00a0 \u00a0response.headers[&#039;subject&#039;] &#061; &#039;python&#039;<br \/>\n \u00a0 \u00a0return response <\/p>\n<h4>\u8fd4\u56dejson\u6570\u636e<\/h4>\n<p>\u5728\u524d\u9762\u5185\u5bb9\u4e2d\u6211\u4eec\u90fd\u662f\u8fd4\u56de\u5b57\u7b26\u4e32&#xff0c;\u4f46\u662f\u5f88\u591aweb\u5f00\u53d1\u4e2d\u90fd\u662f\u8981\u6c42\u524d\u540e\u7aef\u5206\u79bb\u7684&#xff0c;\u524d\u7aef\u4e00\u822c\u4f1a\u8981\u6c42\u540e\u7aef\u8fd4\u56dejson\u6570\u636e\u3002<\/p>\n<p>\u5728django\u7684\u5b66\u4e60\u4e2d\u6211\u4eec\u77e5\u9053\u8fd4\u56dejson\u6570\u636e\u6709\u4e00\u4e2aJsonResponse\u5bf9\u8c61&#xff0c;\u63a5\u6536\u4e00\u4e2apython\u5b57\u5178\u4f5c\u4e3a\u53c2\u6570\u3002Flask\u4e2d\u4e5f\u6709\u4e00\u4e2a\u7c7b\u4f3c\u7684\u5bf9\u8c61\u53ef\u4ee5\u8fd4\u56dejson\u6570\u636e\u3002<\/p>\n<p>make_response\u65b9\u5f0f\u8fd4\u56dejson\u5bf9\u8c61<\/p>\n<p>from flask import Flask,make_response,json<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0my_dict &#061; {&#034;status&#034;:&#039;200&#039;,&#034;object&#034;:&#039;python&#039;}<br \/>\n \u00a0 \u00a0response &#061; make_response(json.dumps(my_dict),200)<br \/>\n \u00a0 \u00a0response.headers[&#039;Content-Type&#039;] &#061; &#039;application\/json&#039;<br \/>\n \u00a0 \u00a0return response<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p>jsonify&#xff1a; \u8fd4\u56dejson\u683c\u5f0f\u7684\u6570\u636e,\u66f4\u52a0\u7b80\u4fbf<\/p>\n<p>from flask import Flask,jsonify<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0my_dict &#061; {&#034;status&#034;:&#039;200&#039;,&#034;object&#034;:&#039;python&#039;}<br \/>\n \u00a0 \u00a0return jsonify(my_dict)<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<h3>Cookie<\/h3>\n<h4>\u8bbe\u7f6ecookie<\/h4>\n<p>cookie \u662f\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u4fdd\u5b58\u5728\u6d4f\u89c8\u5668\u4e2d\u3002<\/p>\n<p>\u8bbe\u7f6ecookie\u6211\u4eec\u6bd4\u8f83\u5173\u5fc3\u7684\u4e09\u4e2a\u53c2\u6570&#xff1a;<\/p>\n<p>key cookie\u7684\u952e<\/p>\n<p>value cookie\u7684\u503c<\/p>\n<p>max_age&#061;None \u8d85\u65f6\u65f6\u95f4&#xff0c;\u5355\u4f4d\u662f\u79d2<\/p>\n<p>expires&#061;None \u8d85\u65f6\u65f6\u95f4&#xff0c;datatime\u5bf9\u8c61<\/p>\n<p>from flask import Flask,make_response<br \/>\n\u200b<br \/>\napp &#061; Flask(__name__)<br \/>\n\u200b<br \/>\n&#064;app.route(&#039;\/&#039;)<br \/>\ndef index():<br \/>\n \u00a0 \u00a0response &#061; make_response(&#039;\u8bbe\u7f6eCookie&#039;)<br \/>\n \u00a0 \u00a0response.status_code &#061; 200<br \/>\n \u00a0 \u00a0# \u8bbe\u7f6eCookie&#xff0c;\u952e\u4e3aname&#xff0c;\u503c\u4e3apython&#xff0c;\u5b58\u6d3b\u65f6\u95f4\u4e3a10\u79d2<br \/>\n \u00a0 \u00a0response.set_cookie(&#039;name&#039;,&#039;python&#039;,max_age&#061;10)<br \/>\n \u00a0 \u00a0return response<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\u7684\u7f13\u5b58\u4e2d&#xff0c;\u67e5\u770bcookie\u503c<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122005-689f25f5dc99c.png\" \/><\/p>\n<h4>\u83b7\u53d6cookie<\/h4>\n<p>&#064;app.route(&#039;\/getcookie&#039;)<br \/>\ndef get_cookie():<br \/>\n \u00a0 \u00a0cookie &#061; request.cookies.get(&#039;name&#039;,&#039;Not Font&#039;)<br \/>\n \u00a0 \u00a0return cookie <\/p>\n<h4>\u5220\u9664cookie<\/h4>\n<p>&#064;app.route(&#039;\/delcookie&#039;)<br \/>\ndef del_cookie():<br \/>\n \u00a0 \u00a0response &#061; make_response(&#039;\u5220\u9664cookie&#039;)<br \/>\n \u00a0 \u00a0response.delete_cookie(&#039;name&#039;)<br \/>\n \u00a0 \u00a0return response <\/p>\n<h3>Session<\/h3>\n<p>\u5728Flask\u4e2d&#xff0c;\u6211\u4eec\u5e76\u6ca1\u6709\u6570\u636e\u5e93\u914d\u7f6e&#xff0c;\u5b9e\u9645\u4e0aFlask\u7684session\u662f\u57fa\u4e8ecookie\u52a0secret_key \u8fdb\u884c\u52a0\u5bc6\u540e\u4fdd\u5b58\u5728cookie\u4e2d\u7684\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122008-689f25f872058.png\" \/><\/p>\n<h4>\u8bbe\u7f6esession<\/h4>\n<p>from flask import Flask,session<br \/>\nimport os<br \/>\napp &#061; Flask(__name__)<br \/>\n# \u8bbe\u7f6esession\u8981\u751f\u6210\u5bc6\u94a5SECRET_KEY<br \/>\napp.config[&#039;SECRET_KEY&#039;] &#061; os.urandom(24)<br \/>\n&#064;app.route(&#039;\/setcookie&#039;)<br \/>\ndef set_cookie():<br \/>\n \u00a0 \u00a0session[&#039;myname&#039;] &#061; &#039;python&#039;<br \/>\n \u00a0 \u00a0session[&#039;password&#039;] &#061; &#039;123456&#039;<br \/>\n \u00a0 \u00a0return &#039;session&#039;<br \/>\n\u200b<br \/>\nif __name__ &#061;&#061; &#039;__main__&#039;:<br \/>\n \u00a0 \u00a0app.run(debug&#061;True,port&#061;8088) <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122011-689f25fb37c5f.png\" \/><\/p>\n<h4>\u83b7\u53d6session<\/h4>\n<p>&#064;app.route(&#039;\/getsession&#039;)<br \/>\ndef get_session():<br \/>\n \u00a0 \u00a0# \u83b7\u53d6session\u91c7\u7528[key]\u65b9\u5f0f\u53d6\u503c&#xff0c;\u5982\u679ckey\u4e0d\u5b58\u5728\u4f1a\u62a5\u9519\u3002<br \/>\n \u00a0 \u00a0myname &#061; session[&#039;myname&#039;]<br \/>\n \u00a0 \u00a0# \u83b7\u53d6session \u91c7\u7528get\u65b9\u5f0f\u53d6\u503c&#xff0c;\u5982\u679ckey\u4e0d\u5b58\u5728\u8fd4\u56deNone<br \/>\n \u00a0 \u00a0password &#061; session.get(&#039;password&#039;,&#034;none&#034;)<br \/>\n \u00a0 \u00a0return f&#039;myname:{myname},password:{password}&#039; <\/p>\n<h4>\u5220\u9664session<\/h4>\n<p>\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528session.pop(&#039;key&#039;,None)&#xff1a;<\/p>\n<p>session.pop(&#039;name&#039;,None)<\/p>\n<p>\u5982\u679c\u8981\u5220\u9664session\u4e2d\u6240\u6709\u6570\u636e\u4f7f\u7528&#xff1a;clear()&#xff1a;<\/p>\n<p>session.clear()<\/p>\n<p>&#064;app.route(&#039;\/delsession&#039;)<br \/>\ndef del_session():<br \/>\n \u00a0 \u00a0# \u5220\u9664key\u4e3amyname<br \/>\n \u00a0 \u00a0session.pop(&#039;myname&#039;,None)<br \/>\n \u00a0 \u00a0# \u5220\u9664\u6240\u6709\u7684<br \/>\n \u00a0 \u00a0session.clear()<br \/>\n \u00a0 \u00a0return &#039;\u5220\u9664session&#039; <\/p>\n<h4>\u8bbe\u7f6esession\u8fc7\u671f\u65f6\u95f4<\/h4>\n<p>Flask\u7684\u9ed8\u8ba4session\u5229\u7528\u4e86Werkzeug\u7684SecureCookie&#xff0c;\u628a\u4fe1\u606f\u505a\u5e8f\u5217\u5316(pickle)\u540e\u7f16\u7801(base64)&#xff0c;\u653e\u5230cookie\u91cc\u4e86\u3002<\/p>\n<p>\u8fc7\u671f\u65f6\u95f4\u662f\u901a\u8fc7cookie\u7684\u8fc7\u671f\u65f6\u95f4\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u4e3a\u4e86\u9632\u6b62cookie\u5185\u5bb9\u88ab\u7be1\u6539&#xff0c;session\u4f1a\u81ea\u52a8\u6253\u4e0a\u4e00\u4e2a\u53ebsession\u7684hash\u4e32&#xff0c;\u8fd9\u4e2a\u4e32\u662f\u7ecf\u8fc7session\u5185\u5bb9\u3001SECRET_KEY\u8ba1\u7b97\u51fa\u6765\u7684&#xff0c;\u770b\u5f97\u51fa&#xff0c;\u8fd9\u79cd\u8bbe\u8ba1\u867d\u7136\u4e0d\u80fd\u4fdd\u8bc1session\u91cc\u7684\u5185\u5bb9\u4e0d\u6cc4\u9732&#xff0c;\u4f46\u81f3\u5c11\u9632\u6b62\u4e86\u4e0d\u88ab\u7be1\u6539\u3002<\/p>\n<p>\u8fc7\u671f\u65f6\u95f4\u662f\u8fd9\u6837\u6765\u8bbe\u7f6e:<\/p>\n<p>from datetime import timedelta<br \/>\napp &#061; Flask(__name__)<br \/>\nsession.permanent &#061; True<br \/>\n# session\u8fc7\u671f\u65f6\u95f4\u8bbe\u7f6e\u4e3a5\u5206\u949f<br \/>\napp.permanent_session_lifetime &#061; timedelta(minutes&#061;5) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb276\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf2\u6b21\u3002Flask\u9519\u8bef\u5904\u7406\u4e0e\u54cd\u5e94\u673a\u5236\u603b\u7ed3\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86Flask\u6846\u67b6\u4e2d\u7684\u9519\u8bef\u5904\u7406\u65b9\u6cd5\u548c\u54cd\u5e94\u673a\u5236\u3002\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\uff1a1\uff09\u4f7f\u7528abort()\u51fd\u6570\u629b\u51faHTTP\u9519\u8bef\uff1b2\uff09\u901a\u8fc7errorhandler\u88c5\u9970\u5668\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\uff08\u5982404\u9875\u9762\uff09\uff1b3\uff09\u54cd\u5e94\u6570\u636e\u7684\u591a\u79cd\u5f62\u5f0f\uff08\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001JSON\uff09\uff1b4\uff09\u4f7f\u7528make_response\u521b\u5efa\u54cd\u5e94\u5bf9\u8c61\uff1b5\uff09\u8bbe\u7f6e\u3001\u83b7\u53d6\u548c\u5220\u9664Cookie\uff1b6\uff09Session\u7684\u914d\u7f6e\u548c\u4f7f\u7528\uff08\u5305\u62ec\u52a0\u5bc6\u3001\u8fc7\u671f\u65f6\u95f4\u8bbe\u7f6e\uff09\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7cbe\u7f8e\u7684404\u9519\u8bef\u9875\u9762\u6a21\u677f\u4ee3\u7801\uff0c\u5c55\u793a\u4e86Flask\u5982\u4f55\u5904\u7406\u7528\u6237\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\u3002<\/p>\n","protected":false},"author":2,"featured_media":57811,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[153,6080,81,292],"topic":[],"class_list":{"0":"post-57816","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-flask","10":"tag-python","11":"tag-292"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/57816.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb276\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf2\u6b21\u3002Flask\u9519\u8bef\u5904\u7406\u4e0e\u54cd\u5e94\u673a\u5236\u603b\u7ed3\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86Flask\u6846\u67b6\u4e2d\u7684\u9519\u8bef\u5904\u7406\u65b9\u6cd5\u548c\u54cd\u5e94\u673a\u5236\u3002\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\uff1a1\uff09\u4f7f\u7528abort()\u51fd\u6570\u629b\u51faHTTP\u9519\u8bef\uff1b2\uff09\u901a\u8fc7errorhandler\u88c5\u9970\u5668\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\uff08\u5982404\u9875\u9762\uff09\uff1b3\uff09\u54cd\u5e94\u6570\u636e\u7684\u591a\u79cd\u5f62\u5f0f\uff08\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001JSON\uff09\uff1b4\uff09\u4f7f\u7528make_response\u521b\u5efa\u54cd\u5e94\u5bf9\u8c61\uff1b5\uff09\u8bbe\u7f6e\u3001\u83b7\u53d6\u548c\u5220\u9664Cookie\uff1b6\uff09Session\u7684\u914d\u7f6e\u548c\u4f7f\u7528\uff08\u5305\u62ec\u52a0\u5bc6\u3001\u8fc7\u671f\u65f6\u95f4\u8bbe\u7f6e\uff09\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7cbe\u7f8e\u7684404\u9519\u8bef\u9875\u9762\u6a21\u677f\u4ee3\u7801\uff0c\u5c55\u793a\u4e86Flask\u5982\u4f55\u5904\u7406\u7528\u6237\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/57816.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-15T12:20:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122002-689f25f283fa8.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57816.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/57816.html\",\"name\":\"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-15T12:20:13+00:00\",\"dateModified\":\"2025-08-15T12:20:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/57816.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/57816.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57816.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/57816.html","og_locale":"zh_CN","og_type":"article","og_title":"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb276\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf2\u6b21\u3002Flask\u9519\u8bef\u5904\u7406\u4e0e\u54cd\u5e94\u673a\u5236\u603b\u7ed3\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86Flask\u6846\u67b6\u4e2d\u7684\u9519\u8bef\u5904\u7406\u65b9\u6cd5\u548c\u54cd\u5e94\u673a\u5236\u3002\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\uff1a1\uff09\u4f7f\u7528abort()\u51fd\u6570\u629b\u51faHTTP\u9519\u8bef\uff1b2\uff09\u901a\u8fc7errorhandler\u88c5\u9970\u5668\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762\uff08\u5982404\u9875\u9762\uff09\uff1b3\uff09\u54cd\u5e94\u6570\u636e\u7684\u591a\u79cd\u5f62\u5f0f\uff08\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001JSON\uff09\uff1b4\uff09\u4f7f\u7528make_response\u521b\u5efa\u54cd\u5e94\u5bf9\u8c61\uff1b5\uff09\u8bbe\u7f6e\u3001\u83b7\u53d6\u548c\u5220\u9664Cookie\uff1b6\uff09Session\u7684\u914d\u7f6e\u548c\u4f7f\u7528\uff08\u5305\u62ec\u52a0\u5bc6\u3001\u8fc7\u671f\u65f6\u95f4\u8bbe\u7f6e\uff09\u3002\u6587\u7ae0\u8fd8\u63d0\u4f9b\u4e86\u7cbe\u7f8e\u7684404\u9519\u8bef\u9875\u9762\u6a21\u677f\u4ee3\u7801\uff0c\u5c55\u793a\u4e86Flask\u5982\u4f55\u5904\u7406\u7528\u6237\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/57816.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-15T12:20:13+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815122002-689f25f283fa8.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/57816.html","url":"https:\/\/www.wsisp.com\/helps\/57816.html","name":"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-15T12:20:13+00:00","dateModified":"2025-08-15T12:20:13+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/57816.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/57816.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/57816.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Flask\u9519\u8bef\u5904\u7406\u4e0e\u4f1a\u8bdd\u6280\u672f\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=57816"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57816\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/57811"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=57816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=57816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=57816"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=57816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}