{"id":120423,"date":"2020-06-19T00:40:23","date_gmt":"2020-06-18T16:40:23","guid":{"rendered":"http:\/\/4563.org\/?p=120423"},"modified":"2020-06-19T00:40:23","modified_gmt":"2020-06-18T16:40:23","slug":"%e6%88%91%e4%bb%8a%e5%a4%a9%e6%98%af%e6%9d%a5%e8%b7%9fmjj%e5%88%86%e4%ba%ab%e4%b8%80%e6%ac%beweb%e6%a1%86%e6%9e%b6%e7%9a%84%e3%80%82","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=120423","title":{"rendered":"\u6211\u4eca\u5929\u662f\u6765\u8ddfMJJ\u5206\u4eab\u4e00\u6b3eWEB\u6846\u67b6\u7684\u3002"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>cnly1987<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u6211\u4eca\u5929\u662f\u6765\u8ddfMJJ\u5206\u4eab\u4e00\u6b3eWEB\u6846\u67b6\u7684\u3002<\/h3>\n<p>  \t\t\u90a3\u5c31\u662fFastApi.<\/p>\n<p>  \u6027\u80fd\u5feb\uff1a\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u548cNodeJS\u548cGo\u76f8\u63d0\u5e76\u8bba\u3002<br \/>  \u5feb\u901f\u5f00\u53d1\uff1a\u5f00\u53d1\u529f\u80fd\u901f\u5ea6\u63d0\u9ad8\u7ea6200%\u81f3300%<br \/>  \u66f4\u5c11\u7684Bug\uff1a<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; Fewer bugs: \u51cf\u5c1140%\u5f00\u53d1\u4eba\u5458\u5bb9\u6613\u5f15\u53d1\u7684\u9519\u8bef<br \/>  \u76f4\u89c2\uff1a\u5b8c\u7f8e\u7684\u7f16\u8f91\u652f\u6301<br \/>  \u7b80\u5355: \u6613\u4e8e\u4f7f\u7528\u548c\u5b66\u4e60\uff0c\u51cf\u5c11\u9605\u8bfb\u6587\u6863\u7684\u65f6\u95f4\u3002<br \/>  \u4ee3\u7801\u7b80\u6d01\uff1a\u5f88\u5927\u7a0b\u5ea6\u4e0a\u51cf\u5c11\u4ee3\u7801\u91cd\u590d\u3002\u6bcf\u4e2a\u53c2\u6570\u53ef\u4ee5\u58f0\u660e\u591a\u4e2a\u529f\u80fd\uff0c\u51cf\u5c11bug\u7684\u53d1\u751f\u3002<br \/>  \u6807\u51c6\u5316\uff1a\u57fa\u4e8e\u5e76\u5b8c\u5168\u517c\u5bb9API\u7684\u5f00\u53d1\u6807\u51c6\uff1aOpenAPI\uff08\u4ee5\u524d\u79f0\u4e3aSwagger\uff09\u548cJSON Schema\u3002<\/p>\n<p>  \u4e0d\u63d0\u6027\u80fd\uff0cDJANGO+DRF \u662f\u6211\u7528\u8fc7\u7684\u6240\u6709web\u6846\u67b6 \u5f00\u53d1\u6700\u5feb\u901f\u7684\u3010\u4ee3\u7801\u91cf\u6700\u5c11\uff0c\u751a\u81f3\u5f88\u591a\u65f6\u5019\u4e0d\u7528\u5199\u4ee3\u7801\uff0cRESTFUL API \u529f\u80fd\u5c31\u5168\u51fa\u6765\u4e86\u3011\uff0c<br \/>  \u3010\u5728\u5feb\u901f\u5f00\u53d1\u8fd9\u65b9\u9762\u3011laravel\u3001go-gin\u3001spring boot\u8fd9\u4e9b \u6839\u672c\u65e0\u6cd5\u6bd4\u80a9\u3002<br \/>  \u4f46\u662f\u5c0f\u578b\u9879\u76ee\u7528django+drf\u6709\u70b9\u81c3\u80bf\u800c\u4e14\uff0cdjango \u8bf4\u5b9e\u8bdd\u6548\u7387\u4e0d\u662f\u5f88\u9ad8\uff0c\u867d\u7136\u8bf4 django3\u53f7\u79f0\u652f\u6301\u5f02\u6b65\uff0c\u4f46\u662f\u6211\u8fd8\u6ca1\u7528\u5230\u3002<\/p>\n<p>  FastApi\u662f\u4e00\u4e2a\u5f02\u6b65\u9ad8\u6548\u7387\u7684python web\u6846\u67b6\u3002<\/p>\n<p>  \u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<p>  from fastapi import FastApi, Depends, HTTPException, Request<br \/>  from starlette.templating import Jinja2Templates<br \/>  import uvicorn<\/p>\n<p>  templates = Jinja2Templates(directory=&quot;templates&quot;)<\/p>\n<p>  app = FastApi()<\/p>\n<p>  @app.get(&quot;\/&quot;)<br \/>  async def read_root():<br \/>  &nbsp; &nbsp; return {&quot;Hello&quot;: &quot;World&quot;}<\/p>\n<p>  #MVC \u6e32\u67d3\u6a21\u677f\u3010jinja2\u3011<br \/>  @app.get(&quot;\/render&quot;)<br \/>  async def read_root(request: Request,):<br \/>  &nbsp; &nbsp; return templates.TemplateResponse(&quot;item.html&quot;, {&quot;request&quot;: request, &quot;id&quot;: id})<\/p>\n<p>  permissions_list = [&#8216;p1&#8217;, &#8216;p2&#8217;]<\/p>\n<p>  def permission_requeried(permisson:str =None):<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if permission and permission in permissions_list :<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return True<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;else:<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise HTTPException(status_code=400, detail=&#8217;\u6743\u9650\u4e0d\u8db3,&#8217;)<\/p>\n<p>  @app.get(&quot;\/&quot;)<br \/>  async def read_root(permission:str=Depends(permission_requeried)):<br \/>  &nbsp; &nbsp; return {&quot;permission&quot;: &quot;permission&quot;}<\/p>\n<p>  if __name__ == &quot;__main__&quot;:<br \/>  &nbsp; &nbsp; uvicorn.run(app=&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=8000, reload=True, debug=True)<\/p>\n<p>  \u5199\u5b8c\u4e0a\u9762\u7684router \u4ed6\u81ea\u5e26API\u6587\u6863\uff0c\u8ba9\u524d\u7aef\u7684\u4eba\u4e00\u770b\u5c31\u660e\u767d<br \/>  https:\/\/fastapi.tiangolo.com\/img\/index\/index-01-swagger-ui-simple.png<\/p>\n<p>  \u5efa\u8baeMJJ\u8bd5\u8bd5\uff0c\u771f\u7684\u5f88\u4e0d\u9519\u989d<br \/>  \u5b98\u7f51\u6587\u6863\uff1ahttps:\/\/fastapi.tiangolo.com\/\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>yrj<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u4e0a\u6b21\u5728\u7fa4\u91cc\u6709\u4e2a\u7fa4\u53cb\u4e5f\u5b89\u5229\u8fc7\uff0c\u662f\u4e0d\u662f\u4f60\uff1f\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u71d5\u5341\u4e09\u4e36<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5f00\u53d1\u56e2\u961f\u662f\u54ea\u56fd\u7684\u9e2d:lol\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u98ce\u94c3<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u7528python\u5199\u7684\u7f51\u7ad9\u7684\u90fd\u4e0d\u884c\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>cnly1987<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tyrj \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-6-19 00:20<br \/>  \u4e0a\u6b21\u5728\u7fa4\u91cc\u6709\u4e2a\u7fa4\u53cb\u4e5f\u5b89\u5229\u8fc7\uff0c\u662f\u4e0d\u662f\u4f60\uff1f<\/p>\n<p> \u4e0d\u662f\uff0c\u6211\u6700\u8fd1\u7528\u4ed6\u505a\u9879\u76ee\u624d\u5b89\u5229\u7684\u3002\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>cnly1987 \u5927\u4f6c\u6709\u8bdd\u8bf4 : &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/120423"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=120423"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/120423\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=120423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=120423"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=120423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}