{"id":125,"date":"2026-08-06T00:31:42","date_gmt":"2026-08-05T16:31:42","guid":{"rendered":"https:\/\/ltrainyard.icu\/?p=125"},"modified":"2026-08-06T00:46:34","modified_gmt":"2026-08-05T16:46:34","slug":"day-29-flask-%e7%bd%91%e9%a1%b5%ef%bc%9a%e8%b7%af%e7%94%b1%e3%80%81%e6%a8%a1%e6%9d%bf%e3%80%81%e8%a1%a8%e5%8d%95%e4%b8%8e-json-%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/ltrainyard.icu\/index.php\/2026\/08\/06\/day-29-flask-%e7%bd%91%e9%a1%b5%ef%bc%9a%e8%b7%af%e7%94%b1%e3%80%81%e6%a8%a1%e6%9d%bf%e3%80%81%e8%a1%a8%e5%8d%95%e4%b8%8e-json-%e6%8e%a5%e5%8f%a3\/","title":{"rendered":"| Day 29 | Flask \u7f51\u9875\uff1a\u8def\u7531\u3001\u6a21\u677f\u3001\u8868\u5355\u4e0e JSON \u63a5\u53e3 |"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 Web \u7684\u672c\u8d28 \u2014\u2014 \u8bf7\u6c42\u4e0e\u54cd\u5e94<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Web\uff08\u4e07\u7ef4\u7f51\uff09\u662f<strong>\u6d4f\u89c8\u5668\uff08\u5ba2\u6237\u7aef\uff09\u5411\u670d\u52a1\u5668\uff08\u670d\u52a1\u7aef\uff09\u53d1\u8bf7\u6c42\u3001\u670d\u52a1\u5668\u8fd4\u56de\u54cd\u5e94\u7684\u5faa\u73af<\/strong>\u3002\u4f60\u6bcf\u5929\u6253\u5f00\u7f51\u9875\uff0c\u672c\u8d28\u90fd\u662f\u6d4f\u89c8\u5668\u53d1 HTTP \u8bf7\u6c42\uff08&#8221;\u6211\u8981\u8fd9\u4e2a\u9875\u9762&#8221;\uff09\u2192 \u670d\u52a1\u5668\u5904\u7406 \u2192 \u8fd4\u56de\u54cd\u5e94\uff08&#8221;\u8fd9\u5c31\u662f\u5185\u5bb9&#8221;\uff09\u3002\u5b66 Web \u5f00\u53d1\u7b2c\u4e00\u4ef6\u4e8b\u5c31\u662f\u5efa\u7acb\u8fd9\u4e2a\u6a21\u578b\u2014\u2014<strong>\u6ca1\u6709\u8bf7\u6c42\u5c31\u6ca1\u6709\u54cd\u5e94<\/strong>\uff0cFlask \u7684\u6bcf\u4e2a\u51fd\u6570\u90fd\u5728\u5904\u7406&#8221;\u67d0\u4e2a\u8bf7\u6c42&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HTTP\uff08\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\uff09\u662f\u6d4f\u89c8\u5668\u548c\u670d\u52a1\u5668\u5bf9\u8bdd\u7684&#8221;\u8bed\u8a00&#8221;\u3002\u4e00\u6b21\u5bf9\u8bdd\u5305\u542b\uff1a<strong>\u8bf7\u6c42\u884c<\/strong>\uff08\u65b9\u6cd5 + \u8def\u5f84\uff0c\u5982 <code>GET \/about<\/code>\uff09\u3001<strong>\u8bf7\u6c42\u5934<\/strong>\uff08\u6d4f\u89c8\u5668\u7c7b\u578b\u3001Cookie \u7b49\u5143\u4fe1\u606f\uff09\u3001<strong>\u8bf7\u6c42\u4f53<\/strong>\uff08POST \u65f6\u643a\u5e26\u7684\u6570\u636e\uff09\uff1b\u54cd\u5e94\u5219\u6709<strong>\u72b6\u6001\u7801<\/strong>\uff08200 \u6210\u529f\u3001404 \u627e\u4e0d\u5230\u3001405 \u65b9\u6cd5\u4e0d\u5141\u8bb8\u3001500 \u670d\u52a1\u5668\u9519\u8bef\uff09\u3001<strong>\u54cd\u5e94\u5934<\/strong>\u3001<strong>\u54cd\u5e94\u4f53<\/strong>\uff08HTML \/ JSON \u5185\u5bb9\uff09\u3002Flask \u628a&#8221;\u89e3\u6790\u8bf7\u6c42\u3001\u7ec4\u88c5\u54cd\u5e94&#8221;\u7684\u810f\u6d3b\u5168\u5e72\u4e86\u2014\u2014\u4f60\u53ea\u7ba1\u5199\u8def\u7531\u51fd\u6570\uff0cHTTP \u7ec6\u8282\u6846\u67b6\u5904\u7406\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf<strong>\u53bb\u9910\u5385\u70b9\u83dc<\/strong>\uff1a\u4f60\uff08\u6d4f\u89c8\u5668\uff09\u5bf9\u670d\u52a1\u5458\uff08\u670d\u52a1\u5668\uff09\u8bf4&#8221;\u6765\u4e00\u4efd\u5bab\u4fdd\u9e21\u4e01&#8221;\uff08\u8bf7\u6c42\uff09\uff0c\u53a8\u623f\u505a\u597d\u540e\u7aef\u4e0a\u6765\uff08\u54cd\u5e94\uff09\u3002\u6bcf\u6b21\u70b9\u83dc\u90fd\u662f\u4e00\u6b21\u72ec\u7acb\u7684&#8221;\u8bf7\u6c42-\u54cd\u5e94&#8221;\uff0c\u670d\u52a1\u5458\u4e0d\u4f1a\u56e0\u4e3a\u4f60\u4e0a\u6b21\u70b9\u8fc7\u5c31\u8bb0\u5f97\u2014\u2014HTTP \u4e5f\u662f<strong>\u65e0\u72b6\u6001<\/strong>\u7684\uff08\u6bcf\u6b21\u8bf7\u6c42\u72ec\u7acb\uff0c\u6240\u4ee5\u8981\u9760 Cookie \/ \u6570\u636e\u5e93\u8bb0\u4f4f\u7528\u6237\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u4e0d\u542f\u52a8\u670d\u52a1\u5668\uff0c\u7528 test_client \u6a21\u62df\u4e00\u6b21\u5b8c\u6574\u7684\u8bf7\u6c42-\u54cd\u5e94\uff08\u53ef\u79bb\u7ebf\u8fd0\u884c\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask\n\napp = Flask(__name__)\n\n@app.route(\"\/\")\ndef home():\n    return \"\u4f60\u597d\uff0cFlask\uff01\"\n\nclient = app.test_client()       # \u6a21\u62df\"\u6d4f\u89c8\u5668\"\nresp = client.get(\"\/\")           # \u53d1\u9001\u8bf7\u6c42\nprint(\"\u72b6\u6001\u7801\uff1a\", resp.status_code)          # 200 = \u6210\u529f\nprint(\"\u54cd\u5e94\u5185\u5bb9\uff1a\", resp.get_data(as_text=True))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u72b6\u6001\u7801\uff1a 200\n\u54cd\u5e94\u5185\u5bb9\uff1a \u4f60\u597d\uff0cFlask\uff01\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>app.test_client()<\/code> \u521b\u5efa&#8221;\u5047\u6d4f\u89c8\u5668&#8221;\u2014\u2014\u4e0d\u53d1\u7f51\u7edc\u8bf7\u6c42\uff0c\u76f4\u63a5\u5728\u7a0b\u5e8f\u5185\u90e8\u6a21\u62df\u5b8c\u6574\u8bf7\u6c42-\u54cd\u5e94\u5faa\u73af\uff1b<code>client.get(\"\/\")<\/code> \u53d1\u51fa\u8bf7\u6c42\uff0cFlask \u8d70\u8def\u7531\u8868\u5339\u914d\u5230 <code>home<\/code> \u51fd\u6570\u5e76\u8c03\u7528\uff1b<code>resp.status_code<\/code> \u770b\u72b6\u6001\u7801\u3001<code>resp.get_data(as_text=True)<\/code> \u770b\u54cd\u5e94\u4f53\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u771f\u5b9e\u542f\u52a8\u670d\u52a1\u5668<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if __name__ == \"__main__\":\n    app.run(host=\"127.0.0.1\", port=2050, debug=True)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>python app.py\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff08\u8282\u9009\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> * Running on http:\/\/127.0.0.1:2050\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>debug=True<\/code> \u662f\u5f00\u53d1\u6a21\u5f0f\uff1a\u6539\u4ee3\u7801\u4fdd\u5b58\u540e\u670d\u52a1\u5668\u81ea\u52a8\u91cd\u542f\uff0c\u62a5\u9519\u65f6\u6d4f\u89c8\u5668\u80fd\u770b\u5230\u8be6\u7ec6\u9519\u8bef\uff08\u4e0a\u7ebf\u65f6\u8bb0\u5f97\u5173\u6389\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u53ea\u770b\u9875\u9762\u5185\u5bb9\uff0c\u4e0d\u770b\u72b6\u6001\u7801 \u2192 \u95ee\u9898\uff1a404\/500 \u4e5f\u53ef\u80fd\u8fd4\u56de\u5185\u5bb9\uff0c\u8bef\u4ee5\u4e3a\u6210\u529f \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148\u770b <code>status_code<\/code> \u518d\u5904\u7406\u5185\u5bb9\uff0c\u5fc5\u8981\u65f6 <code>raise_for_status()<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u4ee5\u4e3a\u670d\u52a1\u5668\u8bb0\u5f97\u4f60\u4e0a\u6b21\u7684\u8bf7\u6c42 \u2192 \u95ee\u9898\uff1aHTTP \u65e0\u72b6\u6001\uff0c\u6bcf\u6b21\u8bf7\u6c42\u76f8\u4e92\u72ec\u7acb \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u9700\u8981&#8221;\u8bb0\u5fc6&#8221;\u5c31\u7528\u6570\u636e\u5e93\u3001Cookie\u3001Session\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u8bf7\u6c42\u54cd\u5e94\u6210\u4e00\u5bf9\uff0c\u72b6\u6001\u7801\u91cc\u770b\u6210\u8d25\uff1bHTTP \u65e0\u8bb0\u5fc6\uff0c\u6570\u636e\u9760\u5b58\u50a8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 \u8def\u7531 \u2014\u2014 URL \u4e0e\u51fd\u6570\u7684\u5bf9\u5e94\u5173\u7cfb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8def\u7531\uff08route\uff09\u662f Web \u6846\u67b6\u6700\u6838\u5fc3\u7684\u6982\u5ff5\uff1a<strong>\u628a\u300c\u7f51\u5740\u8def\u5f84\u300d\u6620\u5c04\u5230\u300cPython \u51fd\u6570\u300d<\/strong>\u3002<code>@app.route(\"\/about\")<\/code> \u7684\u610f\u601d\u662f\u2014\u2014\u7528\u6237\u8bbf\u95ee <code>\/about<\/code> \u8fd9\u4e2a\u7f51\u5740\uff0c\u5c31\u6267\u884c\u5b83\u4e0b\u9762\u90a3\u4e2a\u51fd\u6570\u3002\u6ca1\u6709\u8def\u7531\uff0c\u670d\u52a1\u5668\u5c31\u4e0d\u77e5\u9053&#8221;\u7528\u6237\u8981\u4ec0\u4e48\u3001\u8be5\u6267\u884c\u54ea\u6bb5\u4ee3\u7801&#8221;\uff1b\u6709\u4e86\u8def\u7531\uff0c\u4e00\u4e2a\u7f51\u5740 = \u4e00\u6bb5\u903b\u8f91\uff0c\u7f51\u7ad9\u7684\u6bcf\u4e2a\u9875\u9762\u90fd\u662f\u8fd9\u4e48\u6765\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Flask \u5185\u90e8\u7ef4\u62a4\u4e00\u5f20<strong>\u8def\u7531\u8868<\/strong>\uff08URL \u89c4\u5219 \u2192 \u51fd\u6570\u7684\u6620\u5c04\uff09\u3002\u6536\u5230\u8bf7\u6c42\u540e\uff0cFlask \u62ff\u8bf7\u6c42\u8def\u5f84\u548c\u8def\u7531\u8868\u5339\u914d\uff08\u652f\u6301 <code>\/hello\/&lt;name&gt;<\/code> \u8fd9\u7c7b<strong>\u52a8\u6001\u89c4\u5219<\/strong>\u2014\u2014\u5c16\u62ec\u53f7\u662f\u53d8\u91cf\uff0c\u5339\u914d\u4efb\u610f\u4e00\u6bb5\u6587\u672c\uff0c\u5339\u914d\u5230\u7684\u503c\u81ea\u52a8\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\uff09\uff1b\u5339\u914d\u6210\u529f\u5c31\u8c03\u7528\u51fd\u6570\u5e76\u8fd4\u56de\u54cd\u5e94\uff0c\u5339\u914d\u4e0d\u5230\u5c31\u8fd4\u56de 404\u3002&#8221;\u8def\u7531&#8221;\u4e8c\u5b57\uff0c\u5c31\u662f<strong>\u4e3a\u8bf7\u6c42\u6307\u8def<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8def\u7531\u50cf<strong>\u516c\u53f8\u524d\u53f0\u7684\u5206\u673a\u8868<\/strong>\uff1a\u62e8 <code>8001<\/code> \u8f6c\u8d22\u52a1\u3001\u62e8 <code>8002<\/code> \u8f6c\u4eba\u4e8b\u3002\u4f60\uff08\u6d4f\u89c8\u5668\uff09\u8bbf\u95ee <code>\/about<\/code> \u5c31\u50cf\u62e8\u5206\u673a\uff0c\u524d\u53f0\uff08Flask\uff09\u67e5\u8868\u627e\u5230\u5bf9\u5e94\u7684\u4eba\uff08\u51fd\u6570\uff09\u63a5\u901a\u5e76\u8f6c\u8fbe\u7ed3\u679c\uff1b\u8868\u91cc\u6ca1\u6709\u7684\u53f7\u7801\uff0c\u524d\u53f0\u53ea\u80fd\u56de&#8221;\u67e5\u65e0\u6b64\u53f7&#8221;\uff08404\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u9759\u6001\u8def\u7531 + \u52a8\u6001\u8def\u7531<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask\n\napp = Flask(__name__)\n\n@app.route(\"\/\")                   # \u8bbf\u95ee\u6839\u8def\u5f84 http:\/\/127.0.0.1:2050\/\ndef home():\n    return \"\u4f60\u597d\uff0c\u6211\u662f Flask\uff01\"\n\n@app.route(\"\/hello\/&lt;name&gt;\")        # \u5c16\u62ec\u53f7\u662f\u53d8\u91cf\uff0c\u5339\u914d\u4efb\u610f\u4e00\u6bb5\u6587\u672c\ndef hello(name):                   # \u5339\u914d\u5230\u7684\u503c\u81ea\u52a8\u4f20\u5165\u51fd\u6570\n    return f\"\u4f60\u597d\uff0c{name}\uff01\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>@app.route(...)<\/code> \u662f\u88c5\u9970\u5668\uff08Day 18\uff09\u2014\u2014\u628a\u51fd\u6570&#8221;\u767b\u8bb0&#8221;\u8fdb\u8def\u7531\u8868\uff1b\u8bbf\u95ee <code>\/hello\/\u5c0f\u660e<\/code> \u65f6\uff0cFlask \u628a <code>\u5c0f\u660e<\/code> \u4f5c\u4e3a <code>name<\/code> \u53c2\u6570\u4f20\u5165 <code>hello<\/code>\uff0c\u51fd\u6570\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u5c31\u662f\u54cd\u5e94\u5185\u5bb9\u3002<strong>\u88c5\u9970\u5668\u5728\u8fd9\u91cc\u7684\u771f\u5b9e\u7528\u9014\uff1a\u7ed9\u51fd\u6570\u9644\u52a0&#8221;URL \u5730\u5740&#8221;\u8fd9\u4e2a\u5143\u4fe1\u606f<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u8def\u7531\u51fd\u6570\u540d\u91cd\u590d \u2192 \u95ee\u9898\uff1a\u540e\u9762\u7684\u4f1a\u8986\u76d6\u524d\u9762\u7684\uff08\u540c\u540d\u51fd\u6570\uff09 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u51fd\u6570\u540d\u4fdd\u6301\u552f\u4e00\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u52a8\u6001\u8def\u7531 <code>\/hello\/&lt;name><\/code> \u62fc\u5199\u548c\u51fd\u6570\u53c2\u6570\u4e0d\u4e00\u81f4 \u2192 \u95ee\u9898\uff1a\u62a5 <code>TypeError<\/code>\uff1a\u53c2\u6570\u5bf9\u4e0d\u4e0a \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5c16\u62ec\u53f7\u91cc\u7684\u540d\u5b57\u5fc5\u987b\u548c\u51fd\u6570\u53c2\u6570\u540d\u4e00\u81f4\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5fd8\u4e86 <code>@app.route<\/code> \u88c5\u9970\u5668 \u2192 \u95ee\u9898\uff1a\u51fd\u6570\u8fd8\u5728\uff0c\u4f46\u8bbf\u95ee\u7f51\u5740\u6c38\u8fdc 404 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u68c0\u67e5\u6bcf\u4e2a&#8221;\u9875\u9762\u51fd\u6570&#8221;\u4e0a\u65b9\u90fd\u6709 <code>@app.route<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u7f51\u5740\u7ed1\u51fd\u6570\uff0c\u8def\u7531\u6765\u6307\u8def\uff1b\u5c16\u62ec\u53f7\u662f\u53d8\u91cf\uff0c\u53c2\u6570\u8981\u5bf9\u9f50\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 render_template \u2014\u2014 Python \u548c HTML \u7684\u7ed3\u5408<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>render_template<\/code> \u8ba9 Flask <strong>\u8bfb\u53d6 HTML \u6a21\u677f\u6587\u4ef6\uff0c\u628a Python \u53d8\u91cf\u586b\u8fdb\u53bb\uff0c\u518d\u8fd4\u56de\u5b8c\u6574\u7684 HTML \u9875\u9762<\/strong>\u3002\u7f51\u7ad9\u9875\u9762\u51e0\u4e4e\u90fd\u662f HTML \u6587\u4ef6\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u2014\u2014\u7528\u6a21\u677f\uff0c\u9875\u9762\u6837\u5f0f\uff08HTML\/CSS\uff09\u548c\u903b\u8f91\uff08Python \u6570\u636e\uff09\u5206\u79bb\uff0c\u7ef4\u62a4\u8d77\u6765\u6e05\u6670\u5f97\u591a\u3002\u8fd9\u662f\u524d\u540e\u7aef\u4ea4\u4e92\u7684\u57fa\u7840\uff1a<strong>\u6a21\u677f\u91cc\u7559\u5360\u4f4d\u7b26\uff0cPython \u8d1f\u8d23\u586b\u503c<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Flask \u4f7f\u7528 <strong>Jinja2<\/strong> \u6a21\u677f\u5f15\u64ce\uff1a\u6a21\u677f\u6587\u4ef6\u91cc\u5199\u666e\u901a HTML\uff0c<code>{{ \u53d8\u91cf }}<\/code> \u662f&#8221;\u8f93\u51fa\u5360\u4f4d\u7b26&#8221;\uff08\u628a\u53d8\u91cf\u503c\u63d2\u5165\u9875\u9762\uff09\uff0c<code>{% if %}<\/code> \/ <code>{% for %}<\/code> \u662f&#8221;\u903b\u8f91\u6807\u7b7e&#8221;\uff08\u63a7\u5236\u7247\u6bb5\u663e\u793a\/\u5faa\u73af\uff09\u3002<code>render_template(\"home.html\", title=..., today=...)<\/code> \u7684\u6d41\u7a0b\uff1a\u627e\u5230 <code>templates\/<\/code> \u4e0b\u7684\u6587\u4ef6 \u2192 \u89e3\u6790\u6210\u6a21\u677f \u2192 \u7528\u5173\u952e\u5b57\u53c2\u6570\u586b\u5145\u5360\u4f4d\u7b26 \u2192 \u8f93\u51fa\u6700\u7ec8 HTML\u3002**\u6a21\u677f\u662f&#8221;\u6bcd\u7248&#8221;\uff0c\u6e32\u67d3\u662f&#8221;\u586b\u5b57\u6e38\u620f&#8221;**\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf<strong>\u586b\u7a7a\u9898\u8bd5\u5377<\/strong>\uff1aHTML \u6a21\u677f\u662f\u5370\u597d\u7684\u5377\u5b50\uff0c<code>{{ title }}<\/code> \u662f\u6a2a\u7ebf\u4e0a\u7684\u7a7a\uff1b<code>render_template<\/code> \u662f\u8001\u5e08\u62ff\u7b54\u6848\uff08Python \u53d8\u91cf\uff09\u586b\u8fdb\u53bb\uff0c\u586b\u5b8c\u7684\u5377\u5b50\uff08\u5b8c\u6574 HTML\uff09\u624d\u53d1\u7ed9\u5b66\u751f\uff08\u6d4f\u89c8\u5668\uff09\u3002\u540c\u4e00\u4e2a\u6a21\u677f\u53cd\u590d\u586b\u4e0d\u540c\u7b54\u6848\u2014\u2014\u8fd9\u5c31\u662f&#8221;\u4e00\u4e2a\u6a21\u677f\u6e32\u67d3\u4e0d\u540c\u6570\u636e&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 **\u6a21\u677f\u6587\u4ef6 <code>templates\/home.html<\/code>**\uff08<code>{{ title }}<\/code> \u662f\u5360\u4f4d\u7b26\uff0c\u7531 Python \u586b\u503c\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"zh\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"utf-8\"&gt;\n    &lt;title&gt;\u9996\u9875&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;{{ title }}&lt;\/h1&gt;\n    &lt;p&gt;\u4eca\u5929\u662f {{ today }}&lt;\/p&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2 **\u540e\u7aef <code>app.py<\/code>**\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template\nfrom datetime import date\n\napp = Flask(__name__)\n\n@app.route(\"\/\")\ndef home():\n    return render_template(\n        \"home.html\",             # \u6a21\u677f\u6587\u4ef6\u540d\uff08\u9ed8\u8ba4\u5728 templates\/ \u76ee\u5f55\u627e\uff09\n        title=\"\u6211\u7684 Flask \u7f51\u7ad9\",  # \u5173\u952e\u5b57\u53c2\u6570 = \u6a21\u677f\u91cc\u7684\u53d8\u91cf\u540d\n        today=date.today(),      # \u4f20\u65e5\u671f\u5bf9\u8c61\uff0cJinja2 \u81ea\u52a8\u8f6c\u6210\u5b57\u7b26\u4e32\n    )\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6a21\u677f\u91cc <code>{{ title }}<\/code> \u548c <code>{{ today }}<\/code> \u662f\u5360\u4f4d\u7b26\uff1bPython \u4fa7 <code>render_template<\/code> \u7684\u5173\u952e\u5b57\u53c2\u6570\u4e0e\u5360\u4f4d\u7b26<strong>\u540c\u540d\u5bf9\u5e94<\/strong>\u2014\u2014\u540d\u5b57\u5bf9\u4e0d\u4e0a\uff0c\u9875\u9762\u5c31\u7a7a\u7740\uff08\u4e0d\u62a5\u9519\uff0c\u663e\u793a\u7a7a\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>\u76ee\u5f55\u7ea6\u5b9a<\/strong>\uff1aFlask \u9ed8\u8ba4\u4ece <code>templates\/<\/code> \u76ee\u5f55\u627e\u6a21\u677f\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>project\/backend\/\n\u251c\u2500\u2500 app.py\n\u2514\u2500\u2500 templates\/\n    \u2514\u2500\u2500 home.html\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6a21\u677f\u6587\u4ef6\u6ca1\u653e\u5728 <code>templates\/<\/code> \u76ee\u5f55 \u2192 \u95ee\u9898\uff1a\u62a5 <code>TemplateNotFound<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u76ee\u5f55\u7ed3\u6784\u5fc5\u987b\u662f <code>\u9879\u76ee\/templates\/xxx.html<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>render_template<\/code> \u4f20\u7684\u53d8\u91cf\u540d\u548c\u6a21\u677f\u5360\u4f4d\u7b26\u4e0d\u4e00\u81f4 \u2192 \u95ee\u9898\uff1a\u9875\u9762\u663e\u793a\u7a7a\u767d\uff0c\u4e14\u4e0d\u62a5\u9519\uff0c\u96be\u6392\u67e5 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4e24\u8fb9\u540d\u5b57\u4e25\u683c\u4e00\u81f4\uff08<code>title<\/code> \u2194 <code>title<\/code>\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6a21\u677f\u91cc\u5199 <code>{{ user.name }}<\/code> \u4f46\u4f20\u7684\u662f\u5b57\u5178 \u2192 \u95ee\u9898\uff1a\u5b57\u5178\u8981\u7528\u4e0b\u6807 <code>{{ user[\"name\"] }}<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4f20\u5bf9\u8c61\u7528\u70b9\u53f7\uff0c\u4f20\u5b57\u5178\u7528\u4e0b\u6807\uff08Jinja2 \u90fd\u652f\u6301\uff0c\u522b\u6df7\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u6a21\u677f\u662f\u6bcd\u7248\uff0c\u53d8\u91cf\u6765\u586b\u7a7a\uff1b\u540d\u5b57\u8981\u5bf9\u9f50\uff0c\u76ee\u5f55\u522b\u653e\u9519\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4 GET \u4e0e POST \u2014\u2014 \u4e24\u79cd\u4f20\u6570\u636e\u7684\u59ff\u52bf<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f51\u9875\u8ba9\u7528\u6237\u8f93\u5165\u5185\u5bb9\uff0c\u6700\u5e38\u89c1\u7684\u662f<strong>\u8868\u5355<\/strong>\uff08form\uff09\u3002\u8868\u5355\u63d0\u4ea4\u6570\u636e\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<strong>GET<\/strong> \u628a\u6570\u636e\u62fc\u5728 URL \u95ee\u53f7\u540e\u9762\uff08<code>?city=\u5317\u4eac<\/code>\uff09\uff0c\u9002\u5408\u67e5\u8be2\u3001\u4e66\u7b7e\u53ef\u6536\u85cf\uff1b<strong>POST<\/strong> \u628a\u6570\u636e\u653e\u5728\u8bf7\u6c42\u4f53\u91cc\uff0c\u9002\u5408\u63d0\u4ea4\u64cd\u4f5c\u3001\u9690\u79c1\u6570\u636e\u3002\u533a\u5206\u4e24\u8005\u662f\u5199\u4efb\u4f55 Web \u7a0b\u5e8f\u7684\u57fa\u672c\u529f\u2014\u2014\u63a5\u53e3\u8bbe\u8ba1\u6210 GET \u8fd8\u662f POST\uff0c\u76f4\u63a5\u51b3\u5b9a\u522b\u4eba\u600e\u4e48\u8c03\u7528\u5b83\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GET \u548c POST \u662f HTTP \u7684\u4e24\u79cd<strong>\u8bf7\u6c42\u65b9\u6cd5<\/strong>\uff08method\uff09\u3002GET \u8bed\u4e49\u662f&#8221;\u53d6\u8d44\u6e90&#8221;\uff1a\u53c2\u6570\u7f16\u7801\u8fdb URL\uff08\u957f\u5ea6\u53d7\u9650\u3001\u5730\u5740\u680f\u53ef\u89c1\u3001\u7559\u5728\u5386\u53f2\u8bb0\u5f55\u548c\u65e5\u5fd7\u91cc\uff09\uff1bPOST \u8bed\u4e49\u662f&#8221;\u63d0\u4ea4\u6570\u636e&#8221;\uff1a\u6570\u636e\u653e\u8bf7\u6c42\u4f53\uff08body\uff09\u91cc\uff0c\u5bb9\u91cf\u5927\u3001URL \u4e0d\u53ef\u89c1\u3001\u53ef\u4f20\u6587\u4ef6\u3002Flask \u4fa7\u5bf9\u5e94\u4e24\u79cd\u8bfb\u53d6\uff1aGET \u7528 <code>request.args.get(\"city\")<\/code>\uff0cPOST \u7528 <code>request.form.get(\"city\")<\/code>\u3002<strong>\u6ce8\u610f\uff1aPOST \u4e0d\u662f\u52a0\u5bc6\uff0c\u53ea\u662f\u4e0d\u5728 URL \u4e0a\u66b4\u9732<\/strong>\u2014\u2014\u8981\u4fdd\u5bc6\u5f97\u7528 HTTPS\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GET \u50cf<strong>\u5728\u8d85\u5e02\u95e8\u53e3\u5bf9\u8bb2\u673a\u558a\u8bdd<\/strong>\uff1a&#8221;\u6709\u6ca1\u6709\u725b\u5976\uff1f&#8221;\uff08\u58f0\u97f3\u7a7f\u8fc7\u95e8\u7f1d\uff0c\u8c01\u8def\u8fc7\u90fd\u542c\u5f97\u89c1\uff09\uff1bPOST \u50cf<strong>\u586b\u4e00\u5f20\u8d2d\u7269\u6e05\u5355\u9012\u7ed9\u5e97\u5458<\/strong>\uff1a&#8221;\u6211\u8981\u8fd9\u4e2a\u8fd9\u4e2a\u8fd9\u4e2a&#8221;\uff08\u6e05\u5355\u5185\u5bb9\u5728\u67dc\u53f0\u91cc\u9762\u4f20\u9012\uff0c\u5916\u9762\u770b\u4e0d\u89c1\uff09\u3002\u558a\u8bdd\u9002\u5408&#8221;\u95ee\u4e00\u53e5&#8221;\uff0c\u9012\u5355\u5b50\u9002\u5408&#8221;\u4e0b\u8ba2\u5355&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u540e\u7aef\u4e24\u79cd\u53d6\u53c2\u65b9\u5f0f\u5bf9\u7167<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template, request\n\napp = Flask(__name__)\n\n@app.route(\"\/weather\")\ndef weather_get():\n    city = request.args.get(\"city\", \"\")   # GET\uff1a\u4ece URL \u95ee\u53f7\u540e\u9762\u53d6\n    return render_template(\"search.html\", result={\"city\": city, \"max\": 33, \"min\": 25})\n\n@app.route(\"\/weather\/post\", methods=&#91;\"POST\"])  # \u58f0\u660e\u53ea\u63a5\u53d7 POST\ndef weather_post():\n    city = request.form.get(\"city\", \"\")   # POST\uff1a\u4ece\u8bf7\u6c42\u4f53\u53d6\n    return f\"\u4f60 POST \u63d0\u4ea4\u7684\u57ce\u5e02\u662f\uff1a{city}\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u8868\u5355\u6a21\u677f<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- GET \u8868\u5355\uff1a\u63d0\u4ea4\u540e\u6d4f\u89c8\u5668\u8df3\u8f6c\u5230 \/weather?city=\u5317\u4eac --&gt;\n&lt;form method=\"get\" action=\"\/weather\"&gt;\n    &lt;input type=\"text\" name=\"city\" placeholder=\"\u8f93\u5165\u57ce\u5e02\u540d\"&gt;\n    &lt;button type=\"submit\"&gt;\u67e5\u8be2&lt;\/button&gt;\n&lt;\/form&gt;\n\n&lt;!-- POST \u8868\u5355\uff1amethod \u6539\u6210 post\uff0c\u63d0\u4ea4\u540e\u6570\u636e\u653e\u8fdb\u8bf7\u6c42\u4f53 --&gt;\n&lt;form method=\"post\" action=\"\/weather\/post\"&gt;\n    &lt;input type=\"text\" name=\"city\" placeholder=\"\u8f93\u5165\u57ce\u5e02\u540d\"&gt;\n    &lt;button type=\"submit\"&gt;\u63d0\u4ea4&lt;\/button&gt;\n&lt;\/form&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8868\u5355\u7684 <code>method<\/code> \u51b3\u5b9a\u63d0\u4ea4\u65b9\u5f0f\uff0c<code>action<\/code> \u51b3\u5b9a\u63d0\u4ea4\u5230\u54ea\u4e2a\u8def\u5f84\uff0c<code>name=\"city\"<\/code> \u51b3\u5b9a\u53c2\u6570\u540d\u2014\u2014**<code>name<\/code> \u662f\u53c2\u6570\u540d\u7684\u552f\u4e00\u6765\u6e90**\uff1b\u8def\u7531\u52a0\u4e86 <code>methods=[\"POST\"]<\/code> \u540e\uff0c\u7528 GET \u8bbf\u95ee\u4f1a\u8fd4\u56de <strong>405 Method Not Allowed<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>\u4e09\u79cd\u53d6\u53c2\u65b9\u5f0f\u5bf9\u7167<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>request.args.get(\"\u540d\u5b57\")<\/code>\uff1aGET \u53c2\u6570\uff08URL \u95ee\u53f7\u540e\u9762\uff09<\/li>\n\n\n\n<li><code>request.form.get(\"\u540d\u5b57\")<\/code>\uff1aPOST \u8868\u5355\u53c2\u6570\uff08\u8bf7\u6c42\u4f53\uff09<\/li>\n\n\n\n<li><code>request.json<\/code> \/ <code>request.get_json()<\/code>\uff1aPOST \u7684 JSON \u6570\u636e<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1aPOST \u8868\u5355\u63d0\u4ea4\u62a5 405 \u2192 \u95ee\u9898\uff1a\u8def\u7531\u6ca1\u58f0\u660e\u63a5\u53d7 POST \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u88c5\u9970\u5668\u52a0 <code>methods=[\"POST\"]<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>request.args<\/code> \u548c <code>request.form<\/code> \u7528\u53cd \u2192 \u95ee\u9898\uff1a\u53c2\u6570\u53d6\u4e0d\u5230\uff0c\u5f97\u5230 <code>None<\/code> \/ \u9ed8\u8ba4\u503c \u2192 \u6b63\u786e\u5199\u6cd5\uff1aGET \u7528 args\uff0cPOST \u7528 form\uff0c\u522b\u6df7\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u8868\u5355 <code>name<\/code> \u548c\u540e\u7aef\u53d6\u7684\u540d\u5b57\u4e0d\u4e00\u81f4 \u2192 \u95ee\u9898\uff1a\u53d6\u4e0d\u5230\u503c\uff08\u62fc\u5199\u9519\u662f Web \u5f00\u53d1\u9ad8\u9891 bug\uff09 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>name=\"city\"<\/code> \u2194 <code>request.form.get(\"city\")<\/code> \u4e25\u683c\u4e00\u81f4\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aGET \u62fc\u5728\u95ee\u53f7\u540e\uff0cPOST \u85cf\u5728\u8eab\u4f53\u91cc\uff1bname \u662f\u94a5\u5319\uff0cargs \u914d form\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5 jsonify \u2014\u2014 \u7ed9\u7a0b\u5e8f\u7528\u7684&#8221;\u9875\u9762&#8221;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u505a\u7684\u90fd\u662f\u8fd4\u56de HTML \u7ed9\u6d4f\u89c8\u5668\u770b\u3002\u4f46<strong>\u7a0b\u5e8f\u4e4b\u95f4\u901a\u4fe1\u8981\u7684\u662f\u6570\u636e\uff0c\u4e0d\u662f\u9875\u9762<\/strong>\u3002<code>jsonify<\/code> \u628a Python \u5b57\u5178\/\u5217\u8868\u53d8\u6210 JSON \u5b57\u7b26\u4e32\u8fd4\u56de\uff0c\u5e76\u81ea\u52a8\u8bbe\u7f6e <code>Content-Type: application\/json<\/code>\u2014\u2014\u8fd9\u5c31\u662f\u4e00\u4e2a&#8221;API \u63a5\u53e3&#8221;\uff08\u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u63a5\u53e3\uff0cApplication Programming Interface\uff09\u3002\u73b0\u5728\u5f88\u591a\u7f51\u7ad9\u90fd\u662f&#8221;\u524d\u7aef\u9875\u9762 + \u540e\u7aef API&#8221;\u7684\u67b6\u6784\uff0c\u5b66\u4f1a jsonify\uff0c\u4f60\u5c31\u4ece&#8221;API \u7684\u4f7f\u7528\u8005&#8221;\u53d8\u6210\u4e86&#8221;API \u7684\u63d0\u4f9b\u65b9&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>jsonify<\/code> \u5185\u90e8\u505a\u4e09\u4ef6\u4e8b\uff1a\u628a Python \u5bf9\u8c61\u5e8f\u5217\u5316\u6210 JSON \u5b57\u7b26\u4e32\uff08\u539f\u7406\u540c Day 27 \u7684 <code>json.dumps<\/code>\uff09\u3001\u8bbe\u7f6e\u54cd\u5e94\u5934 <code>Content-Type: application\/json<\/code>\uff08\u544a\u8bc9\u5ba2\u6237\u7aef&#8221;\u8fd9\u662f JSON \u4e0d\u662f HTML&#8221;\uff09\u3001\u8fd4\u56de Response \u5bf9\u8c61\u3002**\u8fd4\u56de JSON \u7684\u63a5\u53e3\uff0c\u672c\u8d28\u5c31\u662f&#8221;\u8fd4\u56de\u4e00\u6bb5\u6709\u7ea6\u5b9a\u683c\u5f0f\u7684\u6587\u672c&#8221;**\u2014\u2014\u8c03\u7528\u65b9\u7528 <code>resp.json()<\/code> \u89e3\u6790\uff0c\u548c\u89e3\u6790\u4efb\u4f55 API \u4e00\u6837\u3002\u72b6\u6001\u7801\u7528\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\uff1a<code>return jsonify({...}), 404<\/code>\uff0c\u8ba9\u8c03\u7528\u65b9&#8221;\u770b\u7801\u8bc6\u7ed3\u679c&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HTML \u9875\u9762\u50cf<strong>\u7ed9\u987e\u5ba2\u770b\u7684\u83dc\u5355<\/strong>\uff08\u56fe\u6587\u5e76\u8302\uff0c\u4eba\u80fd\u770b\u61c2\uff09\uff1bJSON \u63a5\u53e3\u50cf<strong>\u7ed9\u540e\u53a8\u7684\u7535\u5b50\u8ba2\u5355<\/strong>\uff08\u7ed3\u6784\u5316\u6570\u636e\uff0c\u7a0b\u5e8f\u76f4\u63a5\u5904\u7406\uff09\u3002\u4f60\uff08\u8c03\u7528\u65b9\uff09\u5bf9\u7740\u540e\u53a8\u558a\u4e00\u53e5\u6807\u51c6\u683c\u5f0f\u7684\u8bdd\uff0c\u540e\u53a8\uff08API\uff09\u6309\u683c\u5f0f\u56de\u4e00\u6bb5\u6570\u636e\u2014\u2014\u53cc\u65b9\u90fd\u6309\u7ea6\u5b9a\u683c\u5f0f\u4ea4\u6d41\uff0c\u8fd9\u5c31\u662f&#8221;\u63a5\u53e3\u534f\u8bae&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u5199\u4e00\u4e2a JSON API \u63a5\u53e3<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, jsonify, request\n\napp = Flask(__name__)\n\nCITY_WEATHER = {                    # \u6a21\u62df\u7684\"\u57ce\u5e02\u5929\u6c14\u6570\u636e\u5e93\"\n    \"\u5317\u4eac\": {\"max\": 35, \"min\": 25, \"desc\": \"\u6674\"},\n    \"\u4e0a\u6d77\": {\"max\": 33, \"min\": 26, \"desc\": \"\u591a\u4e91\"},\n    \"\u5e7f\u5dde\": {\"max\": 34, \"min\": 27, \"desc\": \"\u9635\u96e8\"},\n}\n\n@app.route(\"\/api\/weather\")\ndef api_weather():\n    city = request.args.get(\"city\", \"\")\n    if city not in CITY_WEATHER:\n        return jsonify({\"error\": f\"\u6ca1\u6709 {city} \u7684\u5929\u6c14\u6570\u636e\"}), 404  # \u67e5\u65e0\u6b64\u57ce\uff1a404 + \u9519\u8bef\u4fe1\u606f\n    return jsonify({\"city\": city, **CITY_WEATHER&#91;city]})          # \u67e5\u5230\u4e86\uff1a200 + \u6570\u636e\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u7528 requests \u8c03\u7528\u81ea\u5df1\u7684\u63a5\u53e3<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests\nresp = requests.get(\"http:\/\/127.0.0.1:2050\/api\/weather\", params={\"city\": \"\u4e0a\u6d77\"})\nprint(\"\u72b6\u6001\u7801\uff1a\", resp.status_code)\ndata = resp.json()\nprint(data&#91;\"city\"], data&#91;\"desc\"], f\"{data&#91;'min']}~{data&#91;'max']}\u2103\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u72b6\u6001\u7801\uff1a 200\n\u4e0a\u6d77 \u591a\u4e91 26~33\u2103\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>**CITY_WEATHER[city]<\/code> \u662f\u5b57\u5178\u5c55\u5f00\uff08Day 8 \u5b66\u8fc7\uff09\u3002<strong>\u63a5\u53e3\u8bbe\u8ba1\u9ec4\u91d1\u6cd5\u5219\uff1a\u6b63\u5e38\u6570\u636e + 200\uff0c\u5f02\u5e38\u60c5\u51b5 + \u660e\u786e\u9519\u8bef\u4fe1\u606f + \u5408\u9002\u72b6\u6001\u7801<\/strong>\u2014\u2014\u8c03\u7528\u65b9\u4e0d\u7528\u731c\u3002<strong>\u6ce8\u610f\u5148\u542f\u52a8\u670d\u52a1\u7aef\uff0c\u518d\u8fd0\u884c\u8c03\u7528\u811a\u672c<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u53ea\u8fd4\u56de <code>jsonify(...)<\/code> \u4e0d\u4f20\u72b6\u6001\u7801 \u2192 \u95ee\u9898\uff1a\u51fa\u9519\u65f6\u4e5f\u662f 200\uff0c\u8c03\u7528\u65b9\u65e0\u6cd5\u5224\u65ad \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5f02\u5e38\u573a\u666f\u52a0\u72b6\u6001\u7801\uff1a<code>jsonify({...}), 404<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5fd8\u4e86 <code>resp.json()<\/code> \u76f4\u63a5\u628a\u54cd\u5e94\u5bf9\u8c61\u5f53\u6570\u636e\u7528 \u2192 \u95ee\u9898\uff1a\u62ff\u5230\u7684\u662f Response \u5bf9\u8c61\u4e0d\u662f\u5b57\u5178 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>.json()<\/code> \u518d\u8bbf\u95ee\u952e\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1aJSON \u91cc\u585e\u4e86 datetime \u5bf9\u8c61 \u2192 \u95ee\u9898\uff1a\u5e8f\u5217\u5316\u62a5\u9519\uff08JSON \u4e0d\u8ba4\u8bc6\u65e5\u671f\u5bf9\u8c61\uff09 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148\u8f6c\u6210\u5b57\u7b26\u4e32\u518d\u653e\u8fdb\u5b57\u5178\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1ajsonify \u51fa\u6570\u636e\uff0c\u72b6\u6001\u7801\u8868\u7ed3\u679c\uff1b\u5148\u770b\u7801\u518d\u770b\u6570\u636e\uff0c\u63a5\u53e3\u7ea6\u5b9a\u8981\u6e05\u695a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6 \u52a8\u624b\u5b9e\u8df5\uff1a\u5929\u6c14\u67e5\u8be2\u7f51\u9875\uff08\u524d\u540e\u7aef\u4ea4\u4e92\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a Open-Meteo \u63a5\u8fdb\u6765\uff0c\u505a\u4e00\u4e2a\u5b8c\u6574\u7684\u5929\u6c14\u67e5\u8be2\u7f51\u9875\u3002<strong>\u540e\u7aef\u4ee3\u7801\u653e <code>project\/backend<\/code>\uff08\u7aef\u53e3 2050\uff09\uff0c\u524d\u7aef\u9875\u9762\u653e <code>project\/frontend<\/code>\uff08\u7aef\u53e3 1050\uff09<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">**\u540e\u7aef Flask \u5e94\u7528 <code>project\/backend\/app.py<\/code>**\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, jsonify, render_template, request\nimport requests\n\napp = Flask(__name__)\n\n# \u57ce\u5e02\u540d -&gt; (\u7eac\u5ea6, \u7ecf\u5ea6)\nCITIES = {\n    \"\u5317\u4eac\": (39.9042, 116.4074),\n    \"\u4e0a\u6d77\": (31.2304, 121.4737),\n    \"\u5e7f\u5dde\": (23.1291, 113.2644),\n    \"\u6df1\u5733\": (22.5431, 114.0579),\n    \"\u6210\u90fd\": (30.5728, 104.0668),\n}\n\ndef fetch_from_open_meteo(city):\n    \"\"\"\u8c03\u7528 Open-Meteo \u514d\u8d39\u5929\u6c14 API\uff0c\u8fd4\u56de\u6700\u8fd1 3 \u5929\u6570\u636e\"\"\"\n    lat, lon = CITIES&#91;city]\n    params = {\n        \"latitude\": lat,\n        \"longitude\": lon,\n        \"daily\": \"temperature_2m_max,temperature_2m_min,weather_code\",\n        \"timezone\": \"Asia\/Shanghai\",\n        \"forecast_days\": 3,\n    }\n    resp = requests.get(\"https:\/\/api.open-meteo.com\/v1\/forecast\",\n                        params=params, timeout=10)\n    resp.raise_for_status()\n    daily = resp.json()&#91;\"daily\"]\n    return &#91;\n        {\"date\": d, \"max\": tmax, \"min\": tmin}\n        for d, tmax, tmin in zip(\n            daily&#91;\"time\"],\n            daily&#91;\"temperature_2m_max\"],\n            daily&#91;\"temperature_2m_min\"],\n        )\n    ]\n\n@app.route(\"\/\")\ndef index():\n    return render_template(\"weather.html\", cities=CITIES.keys())\n\n@app.route(\"\/weather\", methods=&#91;\"POST\"])\ndef weather():\n    city = request.form.get(\"city\", \"\").strip()\n    if city not in CITIES:\n        return render_template(\"weather.html\",\n                               cities=CITIES.keys(),\n                               error=f\"\u4e0d\u652f\u6301\u7684\u57ce\u5e02\uff1a{city}\")\n    try:\n        days = fetch_from_open_meteo(city)\n        return render_template(\"weather.html\",\n                               cities=CITIES.keys(),\n                               city=city,\n                               days=days)\n    except requests.exceptions.RequestException as e:\n        return render_template(\"weather.html\",\n                               cities=CITIES.keys(),\n                               error=f\"\u5929\u6c14\u670d\u52a1\u8bf7\u6c42\u5931\u8d25\uff1a{e}\")\n\n@app.route(\"\/api\/weather\")\ndef api_weather():\n    \"\"\"JSON \u63a5\u53e3\uff1a\u7ed9\u7a0b\u5e8f\u8c03\u7528\u7684\u7248\u672c\uff0c\u6bd4\u5982\u524d\u7aef\u9875\u9762\u7528 fetch \u8c03\u7528\"\"\"\n    city = request.args.get(\"city\", \"\").strip()\n    if city not in CITIES:\n        return jsonify({\"error\": f\"\u4e0d\u652f\u6301\u7684\u57ce\u5e02\uff1a{city}\"}), 400\n    try:\n        return jsonify({\"city\": city, \"days\": fetch_from_open_meteo(city)})\n    except requests.exceptions.RequestException as e:\n        return jsonify({\"error\": str(e)}), 502\n\nif __name__ == \"__main__\":\n    app.run(host=\"127.0.0.1\", port=2050, debug=True)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">**\u6a21\u677f <code>project\/backend\/templates\/weather.html<\/code>**\uff1a\u4e0b\u62c9\u6846\u9009\u57ce\u5e02 + POST \u8868\u5355 + <code>{% if %}<\/code> \/ <code>{% for %}<\/code> \u63a7\u5236\u663e\u793a\uff0c\u9875\u9762\u4e0a\u5c55\u793a <code>{{ city }} \u672a\u6765 3 \u5929\u5929\u6c14<\/code> \u8868\u683c\uff08\u65e5\u671f\/\u6700\u9ad8\u6e29\/\u6700\u4f4e\u6e29\uff09\uff0c\u9519\u8bef\u7528 <code>.error<\/code> \u6837\u5f0f\u663e\u793a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u542f\u52a8\u4e0e\u8bbf\u95ee<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd project\/backend\npip install flask requests\npython app.py\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4f\u89c8\u5668\u8bbf\u95ee <code>http:\/\/127.0.0.1:2050\/<\/code>\uff0c\u9009\u62e9\u57ce\u5e02\u3001\u70b9&#8221;\u67e5\u8be2&#8221;\u5c31\u80fd\u770b\u5230\u771f\u5b9e\u5929\u6c14\u3002\u6574\u4e2a\u6d41\u7a0b\uff1a<strong>\u8868\u5355 POST \u2192 Flask \u63a5\u6536 \u2192 \u540e\u7aef\u8c03 Open-Meteo \u2192 \u6570\u636e\u4f20\u5165\u6a21\u677f \u2192 \u6e32\u67d3\u6210 HTML \u8fd4\u56de<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6269\u5c55\uff1a\u524d\u7aef\u72ec\u7acb\u9875\u9762\u7528 fetch \u8c03\u540e\u7aef\u63a5\u53e3<\/strong>\uff08<code>project\/frontend\/weather.html<\/code>\uff0c\u524d\u540e\u7aef\u5f7b\u5e95\u5206\u79bb\uff09\u2014\u2014\u7528\u4e24\u4e2a\u7ec8\u7aef\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7ec8\u7aef 1\uff1a\u542f\u52a8\u540e\u7aef\ncd project\/backend &amp;&amp; python app.py          # http:\/\/127.0.0.1:2050\n\n# \u7ec8\u7aef 2\uff1a\u542f\u52a8\u524d\u7aef\u9759\u6001\u9875\u9762\ncd project\/frontend &amp;&amp; python -m http.server 1050   # http:\/\/127.0.0.1:1050\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4f\u89c8\u5668\u6253\u5f00 <code>http:\/\/127.0.0.1:1050\/weather.html<\/code>\uff0c\u8f93\u5165\u57ce\u5e02\u540d\u70b9&#8221;\u67e5\u8be2&#8221;\u2014\u2014\u6d4f\u89c8\u5668\u91cc\u7684 JavaScript \u5411\u540e\u7aef <code>\/api\/weather<\/code> \u53d1\u8bf7\u6c42\uff0c\u62ff\u5230 JSON \u540e\u6e32\u67d3\u6210\u8868\u683c\u3002\u8fd9\u5c31\u662f\u771f\u6b63\u7684<strong>\u524d\u540e\u7aef\u5206\u79bb<\/strong>\uff1a\u524d\u7aef\u7ba1\u9875\u9762\uff081050\uff09\uff0c\u540e\u7aef\u7ba1\u6570\u636e\u548c\u903b\u8f91\uff082050\uff09\uff0c\u4e2d\u95f4\u7528 API \u901a\u4fe1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5347\u7ea7\u6311\u6218<\/strong>\uff1a\u5728 JSON \u63a5\u53e3\u91cc\u52a0\u4e0a <code>weather_code<\/code> \u5e76\u7ffb\u8bd1\u6210&#8221;\u6674\/\u591a\u4e91\/\u96e8&#8221;\u8fd9\u6837\u7684\u4e2d\u6587\uff1b\u6216\u8005\u628a day28 \u7684 SQLite \u63a5\u8fdb\u6765\uff0c\u67e5\u8be2\u8fc7\u7684\u57ce\u5e02\u8bb0\u5f55\u5230\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7406\u89e3 Web \u672c\u8d28\uff1a\u6d4f\u89c8\u5668\u53d1\u8bf7\u6c42\u3001\u670d\u52a1\u5668\u56de\u54cd\u5e94\uff0cHTTP \u65e0\u72b6\u6001\uff0c\u72b6\u6001\u7801\uff08200\/404\/405\/500\uff09\u91cc\u770b\u6210\u8d25\n\u8def\u7531 = URL \u4e0e\u51fd\u6570\u7684\u5bf9\u5e94\u5173\u7cfb\uff1a<code>@app.route<\/code> \u88c5\u9970\u5668\u767b\u8bb0\uff0c<code>\/hello\/&lt;name&gt;<\/code> \u52a8\u6001\u53c2\u6570\uff0c\u540d\u5b57\u8981\u548c\u51fd\u6570\u53c2\u6570\u4e00\u81f4\n<code>render_template<\/code> \u6e32\u67d3 HTML \u6a21\u677f\uff1a<code>{{ \u53d8\u91cf }}<\/code> \u5360\u4f4d\u7b26 + \u5173\u952e\u5b57\u53c2\u6570\u540c\u540d\u5bf9\u5e94\uff0c\u6a21\u677f\u653e <code>templates\/<\/code> \u76ee\u5f55\nGET \u4e0e POST\uff1aGET \u53c2\u6570\u5728 URL \u95ee\u53f7\u540e\uff08<code>request.args<\/code>\uff09\uff0cPOST \u6570\u636e\u5728\u8bf7\u6c42\u4f53\uff08<code>request.form<\/code>\uff09\uff0c\u8def\u7531\u8981\u58f0\u660e <code>methods=[\"POST\"]<\/code>\n<code>jsonify<\/code> \u505a JSON API \u63a5\u53e3\uff1a\u6b63\u5e38 200 + \u6570\u636e\uff0c\u5f02\u5e38 4xx\/5xx + \u9519\u8bef\u4fe1\u606f\uff0c\u7528 <code>requests<\/code> \u8c03\u7528\u81ea\u5df1\u7684\u63a5\u53e3\n\u5929\u6c14\u67e5\u8be2\u7f51\u9875\uff1a\u540e\u7aef 2050\uff08\u8868\u5355 POST \u2192 \u8c03 Open-Meteo \u2192 \u6e32\u67d3\u6a21\u677f\uff09\uff0c\u524d\u7aef 1050\uff08fetch \u8c03 JSON \u63a5\u53e3\uff09\uff0c\u524d\u540e\u7aef\u5206\u79bb<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u62a5\u9519<\/th><th>\u539f\u56e0<\/th><th>\u4fee\u590d<\/th><\/tr><\/thead><tbody><tr><td><code>ModuleNotFoundError: No module named 'flask'<\/code><\/td><td>\u6ca1\u5b89\u88c5 Flask<\/td><td>\u547d\u4ee4\u884c\u6267\u884c <code>pip install flask<\/code><\/td><\/tr><tr><td>\u6d4f\u89c8\u5668\u6253\u4e0d\u5f00 127.0.0.1:2050<\/td><td>app.py \u6ca1\u542f\u52a8\uff0c\u6216\u7aef\u53e3\u88ab\u5360\u7528<\/td><td>\u5148\u8fd0\u884c <code>python app.py<\/code>\uff1b\u7aef\u53e3\u88ab\u5360\u5c31\u6362\u7aef\u53e3\uff0c\u6216\u5173\u6389\u5360\u7528\u7aef\u53e3\u7684\u7a0b\u5e8f<\/td><\/tr><tr><td><code>TemplateNotFound: weather.html<\/code><\/td><td>\u6a21\u677f\u4e0d\u5728 <code>templates\/<\/code> \u76ee\u5f55\uff0c\u6216\u6587\u4ef6\u540d\u4e0d\u5bf9<\/td><td>\u786e\u8ba4\u76ee\u5f55\u7ed3\u6784 <code>project\/backend\/templates\/weather.html<\/code>\uff0c\u68c0\u67e5\u6587\u4ef6\u540d\u5927\u5c0f\u5199<\/td><\/tr><tr><td>\u6539\u4ee3\u7801\u540e\u9875\u9762\u6ca1\u53d8\u5316<\/td><td>\u6ca1\u5f00 <code>debug=True<\/code>\uff0c\u670d\u52a1\u5668\u6ca1\u81ea\u52a8\u91cd\u542f<\/td><td>\u52a0 <code>debug=True<\/code> \u91cd\u542f\uff0c\u6216\u624b\u52a8\u91cd\u542f\u670d\u52a1\u5668<\/td><\/tr><tr><td>\u8868\u5355\u63d0\u4ea4\u540e 405 Method Not Allowed<\/td><td>\u8def\u7531\u6ca1\u58f0\u660e POST \u65b9\u6cd5<\/td><td>\u8def\u7531\u88c5\u9970\u5668\u52a0 <code>methods=[\"POST\"]<\/code><\/td><\/tr><tr><td><code>sqlite3.OperationalError<\/code> \/ \u63a5\u53e3 500<\/td><td>\u540e\u7aef\u5185\u90e8\u62a5\u9519\uff08\u6bd4\u5982\u6ca1\u542f\u52a8\u5929\u6c14 API \u4f9d\u8d56\uff09<\/td><td>\u770b\u7ec8\u7aef\u5806\u6808\u4fe1\u606f\uff1b\u68c0\u67e5 <code>CITIES<\/code> \u5b57\u5178\u3001<code>requests<\/code> \u8c03\u7528\u662f\u5426\u6b63\u5e38<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1 Web \u7684\u672c\u8d28 \u2014\u2014 \u8bf7\u6c42\u4e0e\u54cd\u5e94 \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f Web\uff08\u4e07\u7ef4\u7f51\uff09\u662f\u6d4f\u89c8\u5668\uff08\u5ba2\u6237\u7aef\uff09\u5411\u670d\u52a1\u5668\uff08\u670d\u52a1\u7aef\uff09 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[16,9],"tags":[17],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-python","category-code-dev","tag-python-day"],"_links":{"self":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":2,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}