{"id":115251,"date":"2024-02-29T09:02:33","date_gmt":"2024-02-29T01:02:33","guid":{"rendered":"http:\/\/www.zhushiyao.com\/?p=115251"},"modified":"2024-02-29T11:53:00","modified_gmt":"2024-02-29T03:53:00","slug":"%e4%bb%8e-flask-%e5%88%87%e5%88%b0-fastapi-%e5%90%8e%ef%bc%8c%e8%b5%b7%e9%a3%9e%e4%ba%86%ef%bc%81","status":"publish","type":"post","link":"http:\/\/www.zhushiyao.com\/?p=115251","title":{"rendered":"\u4ece Flask \u5207\u5230 FastAPI \u540e\uff0c\u8d77\u98de\u4e86\uff01"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<section style=\"font-size: 16px; color: #3e3e3e; line-height: 1.6; letter-spacing: 0px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;\">\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u672c\u6587\u7ffb\u8bd1\u81ea Moving from Flask to FastAPI\uff0c \u4f5c\u8005\uff1aAmal Shaji<\/p>\n<blockquote style=\"line-height: inherit; border-left-color: #ef7060; margin-top: 20px; margin-bottom: 20px; font-size: 0.9em; overflow: auto; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"color: inherit; line-height: inherit; font-size: 15px;\">\u521a\u597d\u7b14\u8005\u8fd9\u51e0\u5929\u4e0a\u624b\u4f53\u9a8c FastAPI\uff0c\u611f\u53d7\u5230\u8fd9\u4e2a\u6846\u67b6\u6613\u7528\u548c\u65b9\u4fbf\u3002\u4e4b\u524d\u4e5f\u4f7f\u7528\u8fc7 Python \u4e2d\u7684 Django \u548c Flask \u4f5c\u4e3a\u9879\u76ee\u7684\u6846\u67b6\u3002Django \u8bf4\u5b9e\u8bdd\u4e0a\u624b\u4e5f\u65b9\u4fbf\uff0c\u4f46\u662f\u5b66\u4e60\u8d77\u6765\u6709\u70b9\u91cd\u91cf\u7ea7\u6846\u67b6\u7684\u611f\u89c9\uff0cFastAPI \u5e26\u7ed9\u6211\u7684\u76f4\u89c2\u4f53\u9a8c\u8fd8\u662f\u5f88\u8f7b\u4fbf\u7684\uff0c\u672c\u6587\u7ffb\u8bd1\u7684\u8fd9\u7bc7\u6587\u7ae0\u5c31\u4f1a\u7740\u91cd\u4ecb\u7ecd FastAPI \u548c Flask \u7684\u533a\u522b\u3002<\/p>\n<\/blockquote>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Python \u662f\u6700\u6d41\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\u4e4b\u4e00\u3002\u4ece\u811a\u672c\u5230 API \u5f00\u53d1\u518d\u5230\u673a\u5668\u5b66\u4e60\uff0cPython \u90fd\u6709\u7740\u5b83\u81ea\u5df1\u7684\u8db3\u8ff9\u3002\u56e0\u4e3a Python \u6ce8\u91cd\u5f00\u53d1\u8005\u7684\u4f53\u9a8c\u548c\u5176\u6240\u80fd\u63d0\u4f9b\u7684\u5927\u91cf\u5de5\u5177\u800c\u5927\u53d7\u6b22\u8fce\u3002\u7f51\u7edc\u6846\u67b6 Flask \u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u5de5\u5177\uff0c\u5b83\u5728\u673a\u5668\u5b66\u4e60\u793e\u533a\u4e2d\u5f88\u53d7\u6b22\u8fce\u3002\u5b83\u4e5f\u88ab\u5e7f\u6cdb\u7528\u4e8e API\u5f00\u53d1\u3002\u4f46\u662f\u6709\u4e00\u4e2a\u65b0\u7684\u6846\u67b6\u6b63\u5728\u5d1b\u8d77\uff1a FastAPI\u3002\u4e0e Flask \u4e0d\u540c\uff0cFastAPI \u662f\u4e00\u4e2a ASGI\uff08Asynchronous Server Gateway Interface \u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3\uff09\u6846\u67b6\u3002\u4e0e Go \u548c NodeJS \u4e00\u6837\uff0cFastAPI \u662f\u6700\u5feb\u7684\u57fa\u4e8e Python \u7684 Web \u6846\u67b6\u4e4b\u4e00\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u672c\u6587\u9488\u5bf9\u90a3\u4e9b\u6709\u5174\u8da3\u4ece Flask \u8f6c\u79fb\u5230 FastAPI \u7684\u4eba\uff0c\u6bd4\u8f83\u548c\u5bf9\u6bd4\u4e86 Flask \u548c FastAPI \u7684\u5e38\u89c1\u6a21\u5f0f\u3002<\/p>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">FastAPI vs Flask<\/span><\/h2>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u7684\u6784\u5efa\u8003\u8651\u4e86\u4ee5\u4e0b\u4e09\u4e2a\u4e3b\u8981\u95ee\u9898\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u901f\u5ea6<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u5f00\u53d1\u8005\u7ecf\u9a8c<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u5f00\u653e\u6807\u51c6<\/span><\/li>\n<\/ul>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4f60\u53ef\u4ee5\u628a FastAPI \u770b\u4f5c\u662f\u628a Starlette\u3001Pydantic\u3001OpenAPI \u548c JSON Schema \u7c98\u5408\u5728\u4e00\u8d77\u7684\u80f6\u6c34\u3002<\/p>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u672c\u8d28\u4e0a\u8bf4\uff0cFastAPI \u4f7f\u7528 Pydantic \u8fdb\u884c\u6570\u636e\u9a8c\u8bc1\uff0c\u5e76\u4f7f\u7528 Starlette \u4f5c\u4e3a\u5de5\u5177\uff0c\u4f7f\u5176\u4e0e Flask \u76f8\u6bd4\u5feb\u5f97\u60ca\u4eba\uff0c\u5177\u6709\u4e0e Node \u6216 Go \u4e2d\u7684\u9ad8\u901f Web APIs \u76f8\u540c\u7684\u6027\u80fd\u3002<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Starlette + Uvicorn \u63d0\u4f9b\u5f02\u6b65\u8bf7\u6c42\u80fd\u529b\uff0c\u8fd9\u662f Flask \u6240\u7f3a\u4e4f\u7684\u3002<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u6709\u4e86 Pydantic \u4ee5\u53ca\u7c7b\u578b\u63d0\u793a\uff0c\u4f60\u5c31\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u5177\u6709\u81ea\u52a8\u5b8c\u6210\u529f\u80fd\u7684\u826f\u597d\u7684\u7f16\u8f91\u4f53\u9a8c\u3002\u4f60\u8fd8\u53ef\u4ee5\u5f97\u5230\u6570\u636e\u9a8c\u8bc1\u3001\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\uff08\u7528\u4e8e\u6784\u5efa\u4e00\u4e2a API\uff09\uff0c\u4ee5\u53ca\u81ea\u52a8\u5316\u6587\u6863\uff08\u901a\u8fc7 JSON Schema \u548c OpenAPI \uff09\u3002<\/span><\/li>\n<\/ul>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4e5f\u5c31\u662f\u8bf4\uff0cFlask \u7684\u4f7f\u7528\u66f4\u4e3a\u5e7f\u6cdb\uff0c\u6240\u4ee5\u5b83\u7ecf\u8fc7\u4e86\u5b9e\u6218\u68c0\u9a8c\uff0c\u5e76\u4e14\u6709\u66f4\u5927\u7684\u793e\u533a\u652f\u6301\u5b83\u3002\u7531\u4e8e\u8fd9\u4e24\u4e2a\u6846\u67b6\u90fd\u662f\u7528\u6765\u6269\u5c55\u7684\uff0cFlask \u663e\u7136\u662f\u8d62\u5bb6\uff0c\u56e0\u4e3a\u5b83\u6709\u5e9e\u5927\u7684\u63d2\u4ef6\u751f\u6001\u7cfb\u7edf\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5efa\u8bae\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u5982\u679c\u4f60\u5bf9\u4e0a\u8ff0\u4e09\u4e2a\u95ee\u9898\u6709\u5171\u9e23\uff0c\u538c\u5026\u4e86 Flask \u6269\u5c55\u65f6\u7684\u5927\u91cf\u9009\u62e9\uff0c\u5e0c\u671b\u5229\u7528\u5f02\u6b65\u8bf7\u6c42\uff0c\u6216\u8005\u53ea\u662f\u60f3\u5efa\u7acb\u4e00\u4e2a RESTful API\uff0c\u8bf7\u4f7f\u7528 FastAPI\u3002<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u5982\u679c\u4f60\u5bf9 FastAPI \u7684\u6210\u719f\u5ea6\u4e0d\u6ee1\u610f\uff0c\u9700\u8981\u7528\u670d\u52a1\u5668\u7aef\u6a21\u677f\u6784\u5efa\u4e00\u4e2a\u5168\u6808\u5e94\u7528\uff0c\u6216\u8005\u79bb\u4e0d\u5f00\u4e00\u4e9b\u793e\u533a\u7ef4\u62a4\u7684 Flask \u6269\u5c55\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 Flask\u3002<\/span><\/li>\n<\/ul>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5f00\u59cb<\/span><\/h2>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5b89\u88c5<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4e0e\u4efb\u4f55\u5176\u4ed6 Python \u5305\u4e00\u6837\uff0c\u5b89\u88c5\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">pip\u00a0install\u00a0flask\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">\n#<\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">\u00a0or<\/span>\npoetry\u00a0add\u00a0flask\npipenv\u00a0install\u00a0flask\nconda\u00a0install\u00a0flask\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">pip\u00a0install\u00a0fastapi\u00a0uvicorn\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">\n#<\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">\u00a0or<\/span>\npoetry\u00a0add\u00a0fastapi\u00a0uvicorn\npipenv\u00a0install\u00a0fastapi\u00a0uvicorn\nconda\u00a0install\u00a0fastapi\u00a0uvicorn\u00a0-c\u00a0conda-forge\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4e0e Flask \u4e0d\u540c\uff0cFastAPI \u6ca1\u6709\u5185\u7f6e\u7684\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u56e0\u6b64\u9700\u8981\u50cf Uvicorn \u6216 Daphne \u8fd9\u6837\u7684 ASGI \u670d\u52a1\u5668\u3002<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">&#8220;Hello World&#8221; \u5e94\u7528<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0flask_code.py<\/span>\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Flask\n\napp\u00a0=\u00a0Flask(__name__)\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"World\"<\/span>}\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0__name__\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"__main__\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0app.run()\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0fastapi_code.py<\/span>\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0uvicorn\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0FastAPI\n\napp\u00a0=\u00a0FastAPI()\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"World\"<\/span>}\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0__name__\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"__main__\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0uvicorn.run(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"fastapi_code:app\"<\/span>)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u50cf <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">reload=True<\/code> \u8fd9\u6837\u7684\u53c2\u6570\u53ef\u4ee5\u88ab\u4f20\u9012\u5230 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">uvicorn.run()<\/code> \u4e2d\uff0c\u4ee5\u5b9e\u73b0\u5f00\u53d1\u65f6\u7684\u70ed\u91cd\u8f7d\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u4ece\u7ec8\u7aef\u542f\u52a8\u670d\u52a1\u5668\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">uvicorn\u00a0run\u00a0fastapi_code:app\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u70ed\u52a0\u8f7d\u6a21\u5f0f\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">uvicorn\u00a0run\u00a0fastapi_code:app\u00a0--reload\n<\/code><\/pre>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u914d\u7f6e<\/span><\/h2>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u548c FastAPI \u90fd\u63d0\u4f9b\u4e86\u8bb8\u591a\u9009\u9879\u6765\u5904\u7406\u4e0d\u540c\u73af\u5883\u7684\u4e0d\u540c\u914d\u7f6e\u3002\u4e24\u8005\u90fd\u652f\u6301\u4ee5\u4e0b\u6a21\u5f0f\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u73af\u5883\u53d8\u91cf<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u914d\u7f6e\u6587\u4ef6<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u5b9e\u4f8b\u6587\u4ef6\u5939<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">\u7c7b\u548c\u7ee7\u627f<\/span><\/li>\n<\/ol>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u5176\u5404\u81ea\u7684\u6587\u6863\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Flask: https:\/\/flask.palletsprojects.com\/en\/2.0.x\/config\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">FastAPI:https:\/\/fastapi.tiangolo.com\/advanced\/settings\/<\/span><\/li>\n<\/ul>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0os\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Flask\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">Config<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(object)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0MESSAGE\u00a0=\u00a0os.environ.get(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"MESSAGE\"<\/span>)\n\napp\u00a0=\u00a0Flask(__name__)\napp.config.from_object(Config)\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/settings\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">get_settings<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0app.config[<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"MESSAGE\"<\/span>]\u00a0}\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0__name__\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"__main__\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0app.run()\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u73b0\u5728\uff0c\u5728\u4f60\u8fd0\u884c\u670d\u52a1\u5668\u4e4b\u524d\uff0c\u8bbe\u7f6e\u9002\u5f53\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">export\u00a0MESSAGE=\"hello,\u00a0world\"\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0uvicorn\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0FastAPI\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0pydantic\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0BaseSettings\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">Settings<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(BaseSettings)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0message:\u00a0str\n\nsettings\u00a0=\u00a0Settings()\napp\u00a0=\u00a0FastAPI()\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/settings\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">get_settings<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0settings.message\u00a0}\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0__name__\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"__main__\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0uvicorn.run(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"fastapi_code:app\"<\/span>)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u540c\u6837\uff0c\u5728\u8fd0\u884c\u670d\u52a1\u5668\u4e4b\u524d\uff0c\u8bbe\u7f6e\u9002\u5f53\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">export\u00a0MESSAGE=\"hello,\u00a0world\"\n<\/code><\/pre>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u8def\u7531, \u6a21\u677f\u548c\u89c6\u56fe<\/span><\/h2>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">HTTP \u65b9\u6cd5<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0request\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\",\u00a0methods=[\"GET\",\u00a0\"POST\"])<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0handle\u00a0POST<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0request.method\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"POST\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"POST\"<\/span>}\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0handle\u00a0GET<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"GET\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"GET\"<\/span>}\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.post(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home_post<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Hello\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"POST\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u4e3a\u6bcf\u4e2a\u65b9\u6cd5\u63d0\u4f9b\u5355\u72ec\u7684\u88c5\u9970\u5668\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.post(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.delete(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.patch(\"\/\")<\/span>\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">URL \u53c2\u6570<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u901a\u8fc7 URL\uff08\u5982 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">\/employee\/1<\/code> \uff09\u4f20\u9012\u4fe1\u606f\u4ee5\u7ba1\u7406\u72b6\u6001\uff1a<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/employee\/&lt;int:id&gt;\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"id\"<\/span>:\u00a0id}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/employee\/{id}\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(id:\u00a0int)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"id\"<\/span>:\u00a0id}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">URL\u53c2\u6570\u7684\u6307\u5b9a\u7c7b\u4f3c\u4e8e\u4e00\u4e2a f-string \u8868\u8fbe\u5f0f\u3002\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5229\u7528\u7c7b\u578b\u63d0\u793a\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u5728\u8fd0\u884c\u65f6\u544a\u8bc9 Pydantic\uff0c <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">id<\/code> \u662f <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">int<\/code> \u7c7b\u578b\u7684\u3002\u5728\u5f00\u53d1\u4e2d\uff0c\u8fd9\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u5b8c\u6210\u66f4\u597d\u7684\u4ee3\u7801\u5b8c\u6210\u5ea6\u3002<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u67e5\u8be2\u53c2\u6570<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4e0e URL \u53c2\u6570\u4e00\u6837\uff0c\u67e5\u8be2\u53c2\u6570\uff08\u5982 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">\/employee?department=sales<\/code> \uff09\u4e5f\u53ef\u7528\u4e8e\u7ba1\u7406\u72b6\u6001\uff08\u901a\u5e38\u7528\u4e8e\u8fc7\u6ee4\u6216\u6392\u5e8f\uff09\uff1a<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0request\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/employee\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0department\u00a0=\u00a0request.args.get(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"department\"<\/span>)\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"department\"<\/span>:\u00a0department}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/employee\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(department:\u00a0str)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"department\"<\/span>:\u00a0department}\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u6a21\u677f<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0render_template\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0render_template(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"index.html\"<\/span>)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cFlask\u4f1a\u5728 &#8220;templates &#8220;\u6587\u4ef6\u5939\u4e2d\u5bfb\u627e\u6a21\u677f\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4f60\u9700\u8981\u5b89\u88c5 Jinja\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #f0c674; overflow-wrap: inherit !important; word-break: inherit !important;\">pip<\/span>\u00a0install\u00a0jinja2\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5b9e\u73b0\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Request\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.templating\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Jinja2Templates\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.responses\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0HTMLResponse\n\napp\u00a0=\u00a0FastAPI()\n\ntemplates\u00a0=\u00a0Jinja2Templates(directory=<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"templates\"<\/span>)\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\",\u00a0response_class=HTMLResponse)<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(request:\u00a0Request)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0templates.TemplateResponse(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"index.html\"<\/span>,\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"request\"<\/span>:\u00a0request})\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5bf9\u4e8e FastAPI\uff0c\u4f60\u9700\u8981\u660e\u786e\u5730\u5b9a\u4e49 &#8220;\u6a21\u677f &#8220;\u6587\u4ef6\u5939\u3002\u7136\u540e\u5bf9\u4e8e\u6bcf\u4e2a\u54cd\u5e94\uff0c\u9700\u8981\u63d0\u4f9b\u8bf7\u6c42\u4e0a\u4e0b\u6587\u3002<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u9759\u6001\u6587\u4ef6<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cFlask \u4ece\u201cstatic\u201d\u6587\u4ef6\u5939\u4e2d\u63d0\u4f9b\u9759\u6001\u6587\u4ef6\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5728 FastAPI \u4e2d\uff0c\u9700\u8981\u4e3a\u9759\u6001\u6587\u4ef6\u6302\u8f7d\u4e00\u4e2a\u6587\u4ef6\u5939\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.staticfiles\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0StaticFiles\n\napp\u00a0=\u00a0FastAPI()\n\napp.mount(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"\/static\"<\/span>,\u00a0StaticFiles(directory=<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"static\"<\/span>),\u00a0name=<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"static\"<\/span>)\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5f02\u6b65\u4efb\u52a1<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4ece Flask 2.0 \u5f00\u59cb\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">async\/await<\/code> \u521b\u5efa\u5f02\u6b65\u8def\u7531\u5904\u7406\u7a0b\u5e8f\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0result\u00a0=\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">await<\/span>\u00a0some_async_task()\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0result\n<\/code><\/pre>\n<blockquote style=\"line-height: inherit; border-left-color: #ef7060; margin-top: 20px; margin-bottom: 20px; font-size: 0.9em; overflow: auto; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"color: inherit; line-height: inherit; font-size: 15px;\">\u6709\u5173 Flask \u4e2d\u5f02\u6b65\u89c6\u56fe\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b Flask 2.0 \u4e2d\u7684\u5f02\u6b65\u4e00\u6587\u3002<\/p>\n<\/blockquote>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u4e2d\u7684\u5f02\u6b65\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u7ebf\u7a0b\uff08\u5e76\u53d1\uff09\u6216\u591a\u5904\u7406\uff08\u5e76\u884c\uff09\u6216 Celery \u6216 RQ \u7b49\u5de5\u5177\u6765\u5b9e\u73b0\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Asynchronous Tasks with Flask and Celery\uff1ahttps:\/\/testdriven.io\/blog\/flask-and-celery\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Asynchronous Tasks with Flask and Redis Queue\uff1ahttps:\/\/testdriven.io\/blog\/asynchronous-tasks-with-flask-and-redis-queue\/<\/span><\/li>\n<\/ol>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u7531\u4e8e FastAPI \u5bf9 asyncio \u7684\u539f\u751f\u652f\u6301\uff0c\u5b83\u6781\u5927\u5730\u7b80\u5316\u4e86\u5f02\u6b65\u4efb\u52a1\u3002\u8981\u4f7f\u7528\u7684\u8bdd\uff0c\u53ea\u9700\u5728\u89c6\u56fe\u51fd\u6570\u4e2d\u6dfb\u52a0 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">async<\/code> \u5173\u952e\u5b57\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0result\u00a0=\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">await<\/span>\u00a0some_async_task()\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0result\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u8fd8\u5177\u6709\u540e\u53f0\u4efb\u52a1\u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5b9a\u4e49\u8fd4\u56de\u54cd\u5e94\u540e\u8981\u8fd0\u884c\u7684\u540e\u53f0\u4efb\u52a1\u3002\u8fd9\u5bf9\u4e8e\u4e0d\u9700\u8981\u5728\u53d1\u9001\u56de\u54cd\u5e94\u4e4b\u524d\u5b8c\u6210\u7684\u64cd\u4f5c\u5f88\u6709\u7528\u3002<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0BackgroundTasks\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">process_file<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(filename:\u00a0str)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0process\u00a0file\u00a0::\u00a0takes\u00a0minimum\u00a03\u00a0secs\u00a0(just\u00a0an\u00a0example)<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">pass<\/span>\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.post(\"\/upload\/{filename}\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">upload_and_process<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(filename:\u00a0str,\u00a0background_tasks:\u00a0BackgroundTasks)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0background_tasks.add_task(process_file,\u00a0filename)\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"processing\u00a0file\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5728\u8fd9\u91cc\uff0c\u54cd\u5e94\u5c06\u88ab\u5373\u65f6\u53d1\u9001\uff0c\u800c\u4e0d\u4f1a\u8ba9\u7528\u6237\u7b49\u5f85\u6587\u4ef6\u5904\u7406\u5b8c\u6210\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5f53\u4f60\u9700\u8981\u8fdb\u884c\u7e41\u91cd\u7684\u540e\u53f0\u8ba1\u7b97\u65f6\uff0c\u6216\u8005\u4f60\u9700\u8981\u4e00\u4e2a\u4efb\u52a1\u961f\u5217\u6765\u7ba1\u7406\u4efb\u52a1(tasks)\u548c\u5de5\u4f5c\u8005(workers)\u65f6\uff0c\u4f60\u53ef\u80fd\u60f3\u4f7f\u7528Celery \u800c\u4e0d\u662f <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">BackgroundTasks<\/code>\u3002\u66f4\u591a\u5185\u5bb9\u8bf7\u53c2\u8003 FastAPI \u548c Celery \u7684\u5f02\u6b65\u4efb\u52a1\uff1ahttps:\/\/testdriven.io\/blog\/fastapi-and-celery\/<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u4f9d\u8d56\u6ce8\u5165<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u867d\u7136\u4f60\u53ef\u4ee5\u5b9e\u73b0\u81ea\u5df1\u7684\u4f9d\u8d56\u6ce8\u5165\u89e3\u51b3\u65b9\u6848\uff0c\u4f46 Flask \u9ed8\u8ba4\u6ca1\u6709\u771f\u6b63\u7684\u4e00\u6d41\u652f\u6301\u3002\u76f8\u53cd\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u5916\u90e8\u5305\uff0c\u5982 flask-injector\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u53e6\u4e00\u65b9\u9762\uff0cFastAPI \u5177\u6709\u5904\u7406\u4f9d\u8d56\u6ce8\u5165\u7684\u5f3a\u5927\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4f8b\u5982\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0databases\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Database\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Depends\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0starlette.requests\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Request\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0db_helpers\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0get_all_data\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">get_db<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(request:\u00a0Request)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0request.app.state._db\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/data\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">get_data<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(db:\u00a0Database\u00a0=\u00a0Depends<span style=\"font-size: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">(get_db)<\/span>)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0get_all_data(db)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u56e0\u6b64\uff0c<code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">get_db<\/code> \u5c06\u83b7\u53d6\u5bf9\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u542f\u52a8\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u4e2d\u521b\u5efa\u7684\u6570\u636e\u5e93\u8fde\u63a5\u7684\u5f15\u7528\u3002 Depends \u7136\u540e\u7528\u4e8e\u5411 FastAPI \u6307\u793a\u8def\u7531\u201c\u4f9d\u8d56\u4e8e\u201d <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">get_db<\/code>\u3002\u56e0\u6b64\uff0c\u5b83\u5e94\u8be5\u5728\u8def\u7531\u5904\u7406\u7a0b\u5e8f\u4e2d\u7684\u4ee3\u7801\u4e4b\u524d\u6267\u884c\uff0c\u5e76\u4e14\u7ed3\u679c\u5e94\u8be5\u201c\u6ce8\u5165\u201d\u5230\u8def\u7531\u672c\u8eab\u3002<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u6570\u636e\u6821\u9a8c<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u6ca1\u6709\u4efb\u4f55\u5185\u90e8\u6570\u636e\u9a8c\u8bc1\u652f\u6301\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u529f\u80fd\u5f3a\u5927\u7684 Pydantic \u5305\u901a\u8fc7 Flask-Pydantic \u8fdb\u884c\u6570\u636e\u9a8c\u8bc1\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u5982\u6b64\u5f3a\u5927\u7684\u539f\u56e0\u4e4b\u4e00\u662f\u5b83\u652f\u6301 Pydantic\u3002<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0pydantic\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0BaseModel\n\napp\u00a0=\u00a0FastAPI()\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">Request<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(BaseModel)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0username:\u00a0str\n\u00a0\u00a0\u00a0\u00a0password:\u00a0str\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.post(\"\/login\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">login<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(req:\u00a0Request)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0req.username\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"testdriven.io\"<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">and<\/span>\u00a0req.password\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"testdriven.io\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"success\"<\/span>}\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Authentication\u00a0Failed\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u63a5\u53d7\u4e00\u4e2a\u6a21\u578b <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Request<\/code> \u7684\u8f93\u5165\u3002\u8be5 payload \u5fc5\u987b\u5305\u542b\u4e00\u4e2a\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">#<\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">\u00a0correct\u00a0payload\u00a0format<\/span>\n\u2717\u00a0curl\u00a0-X\u00a0POST\u00a0'localhost:8000\/login'\u00a0\n\u00a0\u00a0\u00a0\u00a0--header\u00a0'Content-Type:\u00a0application\/json'\u00a0\n\u00a0\u00a0\u00a0\u00a0--data-raw\u00a0'{\"username\":\u00a0\"testdriven.io\",\"password\":\"testdriven.io\"}'\n\n{\"message\":\"success\"}\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">\n#<\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">\u00a0incorrect\u00a0payload\u00a0format<\/span>\n\u2717\u00a0curl\u00a0-X\u00a0POST\u00a0'localhost:8000\/login'\u00a0\n\u00a0\u00a0\u00a0\u00a0--header\u00a0'Content-Type:\u00a0application\/json'\u00a0\n\u00a0\u00a0\u00a0\u00a0--data-raw\u00a0'{\"username\":\u00a0\"testdriven.io\",\"passwords\":\"testdriven.io\"}'\n\n{\"detail\":[{\"loc\":[\"body\",\"password\"],\"msg\":\"field\u00a0required\",\"type\":\"value_error.missing\"}]}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u6ce8\u610f\u5230\u8fd9\u4e2a\u8bf7\u6c42\u3002\u6211\u4eec\u628a\u5bc6\u7801 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">passwords<\/code> \u4f5c\u4e3a\u4e00\u4e2a\u952e\u800c\u4e0d\u662f <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">password<\/code> \u4f20\u9012\u8fdb\u53bb\u3002Pydantic \u6a21\u578b\u4f1a\u81ea\u52a8\u544a\u8bc9\u7528\u6237\uff0c<code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">password<\/code> \u5b57\u6bb5\u662f\u7f3a\u5931\u7684\u3002<\/p>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u6700\u7b80\u5355\u7684\u5e8f\u5217\u5316\u65b9\u6cd5\u662f\u4f7f\u7528 jsonify\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0jsonify\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0data\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0get_data_as_dict\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">send_data<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0jsonify(get_data_as_dict)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5bf9\u4e8e\u590d\u6742\u7684\u5bf9\u8c61\uff0cFlask \u5f00\u53d1\u8005\u7ecf\u5e38\u4f7f\u7528 Flask-Marshmallow<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u81ea\u52a8\u5e8f\u5217\u5316\u4efb\u4f55\u8fd4\u56de\u7684\u5b57\u5178 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">dict<\/code> \u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u548c\u7ed3\u6784\u5316\u7684\u6570\u636e\uff0c\u4f7f\u7528 Pydantic\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0pydantic\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0BaseModel\n\napp\u00a0=\u00a0FastAPI()\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">Request<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(BaseModel)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0username:\u00a0str\n\u00a0\u00a0\u00a0\u00a0email:\u00a0str\n\u00a0\u00a0\u00a0\u00a0password:\u00a0str\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">Response<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(BaseModel)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0username:\u00a0str\n\u00a0\u00a0\u00a0\u00a0email:\u00a0str\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.post(\"\/login\",\u00a0response_model=Response)<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">login<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(req:\u00a0Request)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0req.username\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"testdriven.io\"<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">and<\/span>\u00a0req.password\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"testdriven.io\"<\/span>:\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0req\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"Authentication\u00a0Failed\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u8f93\u5165\u7684 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Request<\/code> \u6a21\u578b\uff1a\u7528\u6237\u540d\u3001\u7535\u5b50\u90ae\u4ef6\u548c\u5bc6\u7801\u3002\u6211\u4eec\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4ec5\u5305\u542b\u7528\u6237\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u7684 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Response<\/code> \u6a21\u578b\u3002\u8f93\u5165 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Request<\/code> \u6a21\u578b\u5904\u7406\u53cd\u5e8f\u5217\u5316\uff0c\u800c\u8f93\u51fa <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Response<\/code> \u6a21\u578b\u5904\u7406\u5bf9\u8c61\u5e8f\u5217\u5316\u3002\u7136\u540e\u901a\u8fc7 response_model \u53c2\u6570\u5c06\u54cd\u5e94\u6a21\u578b\u4f20\u9012\u7ed9\u88c5\u9970\u5668\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u73b0\u5728\uff0c\u5982\u679c\u6211\u4eec\u5c06\u8bf7\u6c42\u672c\u8eab\u4f5c\u4e3a\u54cd\u5e94\u8fd4\u56de\uff0c<code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">Pydantic<\/code> \u5c06\u7701\u7565 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">password<\/code> \uff0c\u56e0\u4e3a\u6211\u4eec\u5b9a\u4e49\u7684\u54cd\u5e94\u6a21\u578b\u4e0d\u5305\u542b\u5bc6\u7801\u5b57\u6bb5\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4f8b\u5982\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">#<\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">\u00a0output<\/span>\n\u2717\u00a0curl\u00a0-X\u00a0POST\u00a0'localhost:8000\/login'\u00a0\n\u00a0\u00a0\u00a0\u00a0--header\u00a0'Content-Type:\u00a0application\/json'\u00a0\n\u00a0\u00a0\u00a0\u00a0--data-raw\u00a0'{\"username\":\"testdriven.io\",\"email\":\"admin@testdriven.io\",\"password\":\"testdriven.io\"}'\n\n{\"username\":\"testdriven.io\",\"email\":\"admin@testdriven.io\"}\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u4e2d\u95f4\u4ef6<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4e2d\u95f4\u4ef6\u88ab\u7528\u6765\u5728\u6bcf\u4e2a\u8bf7\u6c42\u88ab\u89c6\u56fe\u529f\u80fd\u5904\u7406\u4e4b\u524d\u5e94\u7528\u903b\u8f91\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">class<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">middleware<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">__init__<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(self,\u00a0app)<\/span>\u00a0-&gt;\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">None<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.app\u00a0=\u00a0app\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">__call__<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(self,\u00a0environ,\u00a0start_response)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0start\u00a0=\u00a0time.time()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0response\u00a0=\u00a0self.app(environ,\u00a0start_response)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0end\u00a0=\u00a0time.time()\u00a0-\u00a0start\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">f\"request\u00a0processed\u00a0in\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">{end}<\/span>\u00a0s\"<\/span>)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0response\n\napp\u00a0=\u00a0Flask(__name__)\napp.wsgi_app\u00a0=\u00a0middleware(app.wsgi_app)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Request\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.middleware(\"http\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">add_process_time_header<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(request:\u00a0Request,\u00a0call_next)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0start_time\u00a0=\u00a0time.time()\n\u00a0\u00a0\u00a0\u00a0response\u00a0=\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">await<\/span>\u00a0call_next(request)\n\u00a0\u00a0\u00a0\u00a0process_time\u00a0=\u00a0time.time()\u00a0-\u00a0start_time\n\u00a0\u00a0\u00a0\u00a0print(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">f\"request\u00a0processed\u00a0in\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">{process_time}<\/span>\u00a0s\"<\/span>)\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0response\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">@app.middleware(\"http\")<\/code> \u88c5\u9970\u5668\u662f\u5728 FastAPI \u4e2d\u521b\u5efa\u4e2d\u95f4\u4ef6\u7684\u5fc5\u5907\u5de5\u5177\u3002\u4e0a\u8ff0\u4e2d\u95f4\u4ef6\u8ba1\u7b97\u5904\u7406\u8bf7\u6c42\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u3002\u89c6\u56fe\u51fd\u6570\u5904\u7406\u8bf7\u6c42\u540e\uff0c\u8ba1\u7b97\u603b\u5904\u7406\u65f6\u95f4\u5e76\u5c06\u5176\u4f5c\u4e3a\u54cd\u5e94\u5934\u8fd4\u56de\u3002<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0flask\u00a0output(logs)<\/span>\nrequest\u00a0processed\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">in<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">0.0010077953338623047<\/span>\u00a0s\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">127.0<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">.0<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">.1<\/span>\u00a0-\u00a0-\u00a0[<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">22<\/span>\/Sep\/<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">2020<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">18<\/span>:<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">56<\/span>:<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">21<\/span>]\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"GET\u00a0\/\u00a0HTTP\/1.1\"<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">200<\/span>\u00a0-\n\n<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0fastapi\u00a0output(logs)<\/span>\nrequest\u00a0processed\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">in<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">0.0009925365447998047<\/span>\u00a0s\nINFO:\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">127.0<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">.0<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">.1<\/span>:<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">51123<\/span>\u00a0-\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"GET\u00a0\/\u00a0HTTP\/1.1\"<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">200<\/span>\u00a0OK\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u6a21\u5757\u5316<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u968f\u7740\u5e94\u7528\u7a0b\u5e8f\u7684\u53d1\u5c55\uff0c\u5728\u67d0\u4e9b\u65f6\u5019\u4f60\u4f1a\u60f3\u628a\u7c7b\u4f3c\u7684\u89c6\u56fe\u3001\u6a21\u677f\u3001\u9759\u6001\u6587\u4ef6\u548c\u6a21\u578b\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u4ee5\u5e2e\u52a9\u628a\u5e94\u7528\u7a0b\u5e8f\u5206\u89e3\u6210\u66f4\u5c0f\u7684\u7ec4\u4ef6\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5728 Flask \u4e2d\uff0c\u84dd\u56fe\u88ab\u7528\u6765\u5b9e\u73b0\u6a21\u5757\u5316\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0blueprints\/product\/views.py<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Blueprint\n\nproduct\u00a0=\u00a0Blueprint(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"product\"<\/span>,\u00a0__name__)\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@product.route(\"\/product1\")<\/span>\n\u00a0\u00a0\u00a0\u00a0...\n<\/code><\/pre>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0main.py<\/span>\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0blueprints.product.views\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0product\n\napp.register_blueprint(product)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u540c\u65f6\uff0c\u5728 FastAPI \u4e2d\uff0c\u6a21\u5757\u5316\u662f\u901a\u8fc7 APIRouter \u5b9e\u73b0\u7684\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0routers\/product\/views.py<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0APIRouter\n\nproduct\u00a0=\u00a0APIRouter()\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@product.get(\"\/product1\")<\/span>\n\u00a0\u00a0\u00a0\u00a0...\n<\/code><\/pre>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0main.py<\/span>\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0routers.product.views\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0product\n\napp.include_router(product)\n<\/code><\/pre>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5176\u4ed6\u7279\u70b9<\/span><\/h2>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u81ea\u52a8\u6587\u6863<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u4e0d\u4f1a\u81ea\u52a8\u521b\u5efa\u5f00\u7bb1\u5373\u7528\u7684 API \u6587\u6863\u3002\u7136\u800c\uff0c\u6709\u51e0\u4e2a\u6269\u5c55\u53ef\u4ee5\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\uff0c\u6bd4\u5982 flask-swagger \u548c Flask RESTX\uff0c\u4f46\u5b83\u4eec\u9700\u8981\u989d\u5916\u7684\u8bbe\u7f6e\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cFastAPI \u652f\u6301 OpenAPI \u4ee5\u53ca Swagger UI \u548c ReDoc\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u7aef\u70b9\u90fd\u81ea\u52a8\u4ece\u4e0e\u7aef\u70b9\u5173\u8054\u7684\u5143\u6570\u636e\u4e2d\u8bb0\u5f55\u4e0b\u6765\u3002<\/p>\n<figure style=\"font-size: inherit; color: inherit; line-height: inherit;\"><img class=\"rich_pages wxw-img\" style=\"font-size: inherit; color: inherit; line-height: inherit; display: block; margin-right: auto; margin-left: auto; border-radius: 4px; background: none #f8f8f8; border-width: 1px 1px 2px; border-style: solid; border-color: #cccccc #666666 #999999 #cccccc; padding: 7px;\" title=\"\u6240\u6709\u6ce8\u518c\u7684\u7aef\u70b9\u90fd\u5217\u5728\u8fd9\u91cc\" data-imgfileid=\"100024566\" data-ratio=\"0.30462962962962964\" data-type=\"other\" data-w=\"1080\" \/><figcaption style=\"line-height: inherit; margin-top: 10px; text-align: center; color: #999999; font-size: 0.7em;\">\u6240\u6709\u6ce8\u518c\u7684\u7aef\u70b9\u90fd\u5217\u5728\u8fd9\u91cc<\/figcaption><\/figure>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u6b64\u5904\u5217\u51fa\u4e86\u6240\u6709\u5df2\u6ce8\u518c\u7684\u7aef\u70b9<\/p>\n<figure style=\"font-size: inherit; color: inherit; line-height: inherit;\"><img class=\"rich_pages wxw-img\" style=\"font-size: inherit; color: inherit; line-height: inherit; display: block; margin-right: auto; margin-left: auto; border-radius: 4px; background: none #f8f8f8; border-width: 1px 1px 2px; border-style: solid; border-color: #cccccc #666666 #999999 #cccccc; padding: 7px;\" title=\"\" data-imgfileid=\"100024567\" data-ratio=\"0.48703703703703705\" data-type=\"other\" data-w=\"1080\" \/><figcaption style=\"line-height: inherit; margin-top: 10px; text-align: center; color: #999999; font-size: 0.7em;\"><\/figcaption><\/figure>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u66ff\u4ee3\u6587\u6863<\/p>\n<figure style=\"font-size: inherit; color: inherit; line-height: inherit;\"><img class=\"rich_pages wxw-img\" style=\"font-size: inherit; color: inherit; line-height: inherit; display: block; margin-right: auto; margin-left: auto; border-radius: 4px; background: none #f8f8f8; border-width: 1px 1px 2px; border-style: solid; border-color: #cccccc #666666 #999999 #cccccc; padding: 7px;\" title=\"\" data-imgfileid=\"100024568\" data-ratio=\"0.49722222222222223\" data-type=\"other\" data-w=\"1080\" \/><figcaption style=\"line-height: inherit; margin-top: 10px; text-align: center; color: #999999; font-size: 0.7em;\"><\/figcaption><\/figure>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u7ba1\u7406\u5e94\u7528<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u6709\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9\u7ba1\u7406\u5305\uff0c\u79f0\u4e3a Flask-Admin\uff0c\u7528\u4e8e\u5feb\u901f\u5bf9\u60a8\u7684\u6a21\u578b\u6267\u884c CRUD \u64cd\u4f5c\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u622a\u81f3\u76ee\u524d\uff0c\u6709\u4e24\u4e2a\u6d41\u884c\u7684 FastAPI \u6269\u5c55\u7528\u4e8e\u6b64\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">FastAPI Admin &#8211; \u529f\u80fd\u6027\u7ba1\u7406\u9762\u677f\uff0c\u63d0\u4f9b\u7528\u4e8e\u5bf9\u6570\u636e\u6267\u884c CRUD \u64cd\u4f5c\u7684\u7528\u6237\u754c\u9762\u3002<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">SQLAlchemy Admin -FastAPI\/Starlette \u7684\u7ba1\u7406\u9762\u677f\uff0c\u53ef\u4e0e SQLAlchemy \u6a21\u578b\u4e00\u8d77\u4f7f\u7528\u3002<\/span><\/li>\n<\/ol>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u8eab\u4efd\u8ba4\u8bc1<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u867d\u7136 Flask \u6ca1\u6709\u539f\u751f\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u7b2c\u4e09\u65b9\u6269\u5c55\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u901a\u8fc7 <code style=\"font-size: inherit; line-height: inherit; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #e22446; background: #f8f8f8;\">fastapi.security<\/code> \u5305\u539f\u751f\u652f\u6301\u8bb8\u591a\u5b89\u5168\u548c\u8eab\u4efd\u9a8c\u8bc1\u5de5\u5177\u3002\u901a\u8fc7\u51e0\u884c\u4ee3\u7801\uff0c\u60a8\u53ef\u4ee5\u5c06\u57fa\u672c\u7684 HTTP \u8eab\u4efd\u9a8c\u8bc1\u6dfb\u52a0\u5230\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0secrets\n\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Depends,\u00a0FastAPI,\u00a0HTTPException,\u00a0status\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.security\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0HTTPBasic,\u00a0HTTPBasicCredentials\n\napp\u00a0=\u00a0FastAPI()\n\nsecurity\u00a0=\u00a0HTTPBasic()\n\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">get_current_username<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(credentials:\u00a0HTTPBasicCredentials\u00a0=\u00a0Depends<span style=\"font-size: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">(security)<\/span>)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0correct_username\u00a0=\u00a0secrets.compare_digest(credentials.username,\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"stanleyjobson\"<\/span>)\n\u00a0\u00a0\u00a0\u00a0correct_password\u00a0=\u00a0secrets.compare_digest(credentials.password,\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"swordfish\"<\/span>)\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">if<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">not<\/span>\u00a0(correct_username\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">and<\/span>\u00a0correct_password):\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">raise<\/span>\u00a0HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0credentials.username\n\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/whoami\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">who_ami_i<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">(username:\u00a0str\u00a0=\u00a0Depends<span style=\"font-size: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\">(get_current_username)<\/span>)<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"username\"<\/span>:\u00a0username}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u901a\u8fc7 OpenAPI \u6807\u51c6\u5b9e\u73b0 OAuth2 \u548c OpenID Connect\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u67e5\u770b\u5b98\u65b9\u6587\u6863\u4e2d\u7684\u4ee5\u4e0b\u8d44\u6e90\u4ee5\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Security Intro\uff1ahttps:\/\/fastapi.tiangolo.com\/tutorial\/security\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Advanced Security:https:\/\/fastapi.tiangolo.com\/advanced\/security\/<\/span><\/li>\n<\/ol>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">\u5176\u4ed6\u8d44\u6e90<\/strong><\/p>\n<ol class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Web Authentication Methods Compared\uff1ahttps:\/\/testdriven.io\/blog\/web-authentication-methods\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Adding Social Authentication to Flask:https:\/\/testdriven.io\/blog\/flask-social-auth\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Session-based Auth with Flask for Single Page Apps:https:\/\/testdriven.io\/blog\/flask-spa-auth\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Securing FastAPI with JWT Token-based Authentication\uff1ahttps:\/\/testdriven.io\/blog\/fastapi-jwt-auth\/<\/span><\/li>\n<\/ol>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">CORS<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">CORS\uff08\u8de8\u6e90\u8d44\u6e90\u5171\u4eab\uff09\u4e2d\u95f4\u4ef6\u68c0\u67e5\u8bf7\u6c42\u662f\u5426\u6765\u81ea\u5141\u8bb8\u7684\u6765\u6e90\u3002\u5982\u679c\u662f\uff0c\u5219\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6216\u89c6\u56fe\u51fd\u6570\u3002\u5982\u679c\u4e0d\u662f\uff0c\u5b83\u4f1a\u62d2\u7edd\u8bf7\u6c42\uff0c\u5e76\u5c06\u9519\u8bef\u54cd\u5e94\u53d1\u9001\u56de\u8c03\u7528\u8005\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong> Flask \u9700\u8981\u4e00\u4e2a\u540d\u4e3a Flask-CORS \u7684\u5916\u90e8\u5305\u6765\u652f\u6301 CORS\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">pip\u00a0install\u00a0flask-cors\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u57fa\u672c\u5b9e\u73b0\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask_cors\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0CORS\n\napp\u00a0=\u00a0Flask(__name__)\n\nCORS(app)\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u539f\u751f\u652f\u6301 CORS\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.middleware.cors\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0CORSMiddleware\n\napp\u00a0=\u00a0FastAPI()\n\norigins\u00a0=\u00a0[<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"*\"<\/span>]\n\napp.add_middleware(CORSMiddleware,\u00a0allow_origins=origins)\n<\/code><\/pre>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u6d4b\u8bd5<\/span><\/h2>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0pytest\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0flask\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0Flask\n\napp\u00a0=\u00a0Flask(__name__)\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.route(\"\/\")<\/span>\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"OK\"<\/span>}\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">test_hello<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0res\u00a0=\u00a0app.test_client().get(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"\/\"<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">assert<\/span>\u00a0res.status_code\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">200<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">assert<\/span>\u00a0res.data\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">b'{\"message\":\"OK\"}n'<\/span>\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0FastAPI\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">from<\/span>\u00a0fastapi.testclient\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">import<\/span>\u00a0TestClient\n\napp\u00a0=\u00a0FastAPI()\n\n<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">@app.get(\"\/\")<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">async<\/span>\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">return<\/span>\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"OK\"<\/span>}\n\nclient\u00a0=\u00a0TestClient(app)\n\n<span style=\"font-size: inherit; color: inherit; line-height: inherit; overflow-wrap: inherit !important; word-break: inherit !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">def<\/span>\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #81a2be; overflow-wrap: inherit !important; word-break: inherit !important;\">test_home<\/span><span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">()<\/span>:<\/span>\n\u00a0\u00a0\u00a0\u00a0res\u00a0=\u00a0client.get(<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"\/\"<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">assert<\/span>\u00a0res.status_code\u00a0==\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">200<\/span>\n\u00a0\u00a0\u00a0\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">assert<\/span>\u00a0res.json()\u00a0==\u00a0{<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"message\"<\/span>:\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"OK\"<\/span>}\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">FastAPI \u63d0\u4f9b\u4e86\u4e00\u4e2a TestClient\u3002\u6709\u4e86\u5b83\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u7528 FastAPI \u8fd0\u884c pytest\u3002\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b\u5b98\u65b9\u6587\u6863\u4e2d\u7684\u6d4b\u8bd5\u6307\u5357\u3002<\/p>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u90e8\u7f72<\/span><\/h2>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u751f\u4ea7\u670d\u52a1\u5668<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">Flask \u9ed8\u8ba4\u8fd0\u884c\u5f00\u53d1 WSGI\uff08Web \u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3\uff09\u5e94\u7528\u7a0b\u5e8f\u670d\u52a1\u5668\u3002\u5bf9\u4e8e\u751f\u4ea7\u73af\u5883\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u751f\u4ea7\u7ea7 WSGI \u5e94\u7528\u670d\u52a1\u5668\uff0c\u4f8b\u5982 Gunicorn\u3001uWSGI \u6216 mod_wsgi<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5b89\u88c5 Gunicorn:<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">pip\u00a0install\u00a0gunicorn\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0main.py<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0app\u00a0=\u00a0Flask(__name__)<\/span>\n\ngunicorn\u00a0main:app\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u7531\u4e8e FastAPI \u6ca1\u6709\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u60a8\u5c06\u4f7f\u7528 Uvicorn\uff08\u6216 Daphne\uff09\u8fdb\u884c\u5f00\u53d1\u548c\u751f\u4ea7\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u5b89\u88c5 Uvicorn\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #f0c674; overflow-wrap: inherit !important; word-break: inherit !important;\">pip<\/span>\u00a0install\u00a0uvicorn\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">python\n<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0main.py<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0app\u00a0=\u00a0FastAPI()<\/span>\n\nuvicorn\u00a0main:app\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u60a8\u53ef\u80fd\u5e0c\u671b\u4f7f\u7528 Gunicorn \u6765\u7ba1\u7406 Uvicorn\uff0c\u4ee5\u4fbf\u540c\u65f6\u5229\u7528\u5e76\u53d1\u6027\uff08\u901a\u8fc7 Uvicorn\uff09\u548c\u5e76\u884c\u6027\uff08\u901a\u8fc7 Gunicorn worker\uff09\uff1a<\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\"><span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0main.py<\/span>\n<span style=\"font-size: inherit; line-height: inherit; color: #969896; overflow-wrap: inherit !important; word-break: inherit !important;\">#\u00a0app\u00a0=\u00a0FastAPI()<\/span>\n\ngunicorn\u00a0-w\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">3<\/span>\u00a0-k\u00a0uvicorn.workers.UvicornWorker\u00a0main:app\n<\/code><\/pre>\n<h3 style=\"color: inherit; font-weight: bold; cursor: text; font-size: 1.1em; line-height: 1.43; margin: 1.6em auto 1.2em; padding-left: 9px; border-left: 5px solid #f22f27;\">\u00a0<span style=\"font-size: inherit; color: inherit; line-height: inherit;\">Docker<\/span><\/h3>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">Flask<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">FROM\u00a0python3.10-slim\n\nWORKDIR\u00a0\/app\n\nCOPY\u00a0requirements.txt\u00a0.\n\nRUN\u00a0pip\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">install<\/span>\u00a0-r\u00a0requirements.txt\n\nCOPY\u00a0.\u00a0.\n\nEXPOSE\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">5000<\/span>\n\nCMD\u00a0[<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"gunicorn\"<\/span>,\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"main:app\"<\/span>]\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u8fd9\u662f Flask \u6700\u7b80\u5355\u7684 Dockerfile \u4e4b\u4e00\u3002\u8981\u4e86\u89e3\u5982\u4f55\u9488\u5bf9\u751f\u4ea7\u5bf9\u5176\u8fdb\u884c\u5168\u9762\u914d\u7f6e\uff0c\u8bf7\u67e5\u770b\u4f7f\u7528 Postgres\u3001Gunicorn \u548c Nginx \u6559\u7a0b\u5bf9 Flask \u8fdb\u884c Docker \u5316\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\"><strong style=\"font-size: inherit; line-height: inherit; color: #ff3502;\">FastAPI<\/strong><\/p>\n<pre style=\"font-size: inherit; color: inherit; line-height: inherit;\"><code style=\"margin-right: 2px; margin-left: 2px; line-height: 15px; font-size: 11px; word-spacing: -3px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 5px; background: #1d1f21; color: #c5c8c6; padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;\">sql\nFROM\u00a0python3.10-slim\n\nWORKDIR\u00a0\/app\n\nCOPY\u00a0requirements.txt\u00a0.\n\nRUN\u00a0pip\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b294bb; overflow-wrap: inherit !important; word-break: inherit !important;\">install<\/span>\u00a0-r\u00a0requirements.txt\n\nCOPY\u00a0.\u00a0.\n\nEXPOSE\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #de935f; overflow-wrap: inherit !important; word-break: inherit !important;\">8000<\/span>\n\nCMD\u00a0[<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"uvicorn\"<\/span>,\u00a0<span style=\"font-size: inherit; line-height: inherit; color: #b5bd68; overflow-wrap: inherit !important; word-break: inherit !important;\">\"main:app\"<\/span>]\n<\/code><\/pre>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u540c\u6837\uff0c\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u914d\u7f6e\u3002 FastAPI \u4f5c\u8005\u63d0\u4f9b\u4e86\u51e0\u4e2a\u751f\u4ea7\u5c31\u7eea\u7684 Dockerfile\u3002\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b\u5b98\u65b9 FastAPI \u6587\u6863\u4ee5\u53ca Dockerizing FastAPI with Postgres\u3001Uvicorn \u548c Traefik \u6559\u7a0b\u3002<\/p>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u9000\u4e00\u6b65\u8bb2\uff0cDjango \u548c Flask \u662f\u4e24\u4e2a\u6700\u6d41\u884c\u7684\u57fa\u4e8e Python \u7684\u7f51\u7edc\u6846\u67b6\uff08FastAPI \u662f\u7b2c\u4e09\u5927\u6d41\u884c\u6846\u67b6\uff09\u3002\u4e0d\u8fc7\u5b83\u4eec\uff08Django \u548c Flask\uff09\u7684\u7406\u5ff5\u975e\u5e38\u4e0d\u540c\u3002Flask \u6bd4 Django \u7684\u4f18\u52bf\u5728\u4e8e Flask \u662f\u4e00\u4e2a\u5fae\u6846\u67b6\u3002\u7a0b\u5e8f\u7ed3\u6784\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u51b3\u5b9a\uff0c\u4e0d\u5f3a\u5236\u6267\u884c\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u5728\u4ed6\u4eec\u8ba4\u4e3a\u5408\u9002\u7684\u65f6\u5019\u6dfb\u52a0\u7b2c\u4e09\u65b9\u6269\u5c55\u6765\u6539\u8fdb\u4ed6\u4eec\u7684\u4ee3\u7801\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u968f\u7740\u4ee3\u7801\u5e93\u7684\u589e\u957f\uff0c\u9700\u8981\u4e00\u4e9b\u51e0\u4e4e\u6240\u6709\u7f51\u7edc\u5e94\u7528\u90fd\u9700\u8981\u7684\u901a\u7528\u529f\u80fd\u3002\u8fd9\u4e9b\u529f\u80fd\u4e0e\u6846\u67b6\u7684\u7d27\u5bc6\u7ed3\u5408\uff0c\u4f7f\u5f97\u7ec8\u7aef\u5f00\u53d1\u8005\u9700\u8981\u81ea\u5df1\u521b\u5efa\u548c\u7ef4\u62a4\u7684\u4ee3\u7801\u5927\u5927\u51cf\u5c11\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u672c\u6587\u4e2d\u7684\u4ee3\u7801\u5b9e\u4f8b\u4e5f\u8868\u8fbe\u4e86\u540c\u6837\u7684\u610f\u601d\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cFastAPI \u5305\u62ec\u8bb8\u591a\u5fc5\u8981\u7684\u529f\u80fd\u3002\u5b83\u8fd8\u9075\u5faa\u4e25\u683c\u7684\u6807\u51c6\uff0c\u4f7f\u4f60\u7684\u4ee3\u7801\u53ef\u4ee5\u751f\u4ea7\u5e76\u66f4\u5bb9\u6613\u7ef4\u62a4\u3002FastAPI \u7684\u6587\u6863\u4e5f\u975e\u5e38\u5b8c\u5584\u3002<\/p>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u867d\u7136 FastAPI \u53ef\u80fd\u4e0d\u50cf Flask \u90a3\u6837\u4e45\u7ecf\u8003\u9a8c\uff0c\u4f46\u8d8a\u6765\u8d8a\u591a\u7684\u5f00\u53d1\u4eba\u5458\u6b63\u5728\u8f6c\u5411\u5b83\u6765\u63d0\u4f9b\u673a\u5668\u5b66\u4e60\u6a21\u578b\u6216\u5f00\u53d1 RESTful API\u3002\u5207\u6362\u5230 FastAPI \u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5b98\u65b9\u6587\u6863<\/span><\/h2>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">FastAPI\uff1ahttps:\/\/fastapi.tiangolo.com\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Flask\uff1ahttps:\/\/flask.palletsprojects.com\/en\/2.0.x\/<\/span><\/li>\n<\/ul>\n<h2 style=\"color: inherit; font-weight: bold; cursor: text; margin: 2em auto 1.4em; line-height: 1.4; font-size: 1.2em; border-bottom: 1px solid #f22f27;\"><span style=\"color: #f22f27;\"># <\/span><span style=\"font-size: inherit; color: inherit; line-height: inherit;\">\u5176\u4ed6\u8d44\u6e90<\/span><\/h2>\n<ul class=\"list-paddingleft-1\" style=\"font-size: inherit; line-height: inherit; padding-left: 32px; color: #db4d52;\">\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Porting Flask to FastAPI for ML Model Serving\uff1ahttps:\/\/www.pluralsight.com\/tech-blog\/porting-flask-to-fastapi-for-ml-model-serving\/<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Why we switched from Flask to FastAPI for production machine learning\uff1ahttps:\/\/towardsdatascience.com\/why-we-switched-from-flask-to-fastapi-for-production-machine-learning-765aab9b3679<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Awesome Flask:https:\/\/github.com\/mjhea0\/awesome-flask<\/span><\/li>\n<li style=\"font-size: inherit; color: inherit; line-height: inherit; margin-bottom: 0.5em;\"><span style=\"line-height: inherit; color: #3e3e3e; font-size: 15px;\">Awesome FastAPI:https:\/\/github.com\/mjhea0\/awesome-fastapi<\/span><\/li>\n<\/ul>\n<p style=\"color: inherit; line-height: inherit; margin-top: 1.5em; margin-bottom: 1.5em; font-size: 15px;\">\u4f5c\u8005\uff1a\u5b87\u5b99\u4e4b\u4e00\u7c9f<br \/>\n\u94fe\u63a5\uff1ahttps:\/\/juejin.cn\/post\/7219225476706140218<\/p>\n<p style=\"margin-bottom: 0px; white-space: normal; color: #3e3e3e; max-width: 100%; letter-spacing: 0.544px; background-color: #ffffff; font-family: -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; widows: 1; font-size: 15px; word-spacing: 1.6px; text-align: center; text-size-adjust: auto; caret-color: #3e3e3e; box-sizing: border-box !important; overflow-wrap: break-word !important;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"letter-spacing: 0.544px; box-sizing: border-box !important; overflow-wrap: break-word !important; visibility: visible !important; width: 247px !important;\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2024\/02\/wxsync-2024-02-3fd1c09fc16669c39adc70d579cbf395.jpeg\" data-copyright=\"0\" data-ratio=\"0.07625\" data-s=\"300,640\" data-type=\"jpeg\" data-w=\"800\" data-imgfileid=\"100024569\" \/><\/p>\n<\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81ea Moving from Flask to FastAPI\uff0c \u4f5c\u8005\uff1aAmal Shaji \u521a\u597d\u7b14\u8005\u8fd9 &hellip; <a href=\"http:\/\/www.zhushiyao.com\/?p=115251\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u4ece Flask \u5207\u5230 FastAPI \u540e\uff0c\u8d77\u98de\u4e86\uff01\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[8],"_links":{"self":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/115251"}],"collection":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=115251"}],"version-history":[{"count":1,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/115251\/revisions"}],"predecessor-version":[{"id":115252,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/115251\/revisions\/115252"}],"wp:attachment":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=115251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=115251"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=115251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}