{"id":204794,"date":"2025-05-29T15:13:53","date_gmt":"2025-05-29T07:13:53","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204794\/"},"modified":"2025-05-29T15:13:53","modified_gmt":"2025-05-29T07:13:53","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-python-flask-%e6%a1%86%e6%9e%b6%e4%b8%ad%e5%ae%9e%e7%8e%b0%e7%b1%bb%e4%bc%bc-laravel-%e4%b8%ad%e9%97%b4%e4%bb%b6%e7%9a%84%e8%af%b7%e6%b1%82%e6%8b%a6%e6%88%aa%e5%8a%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204794\/","title":{"rendered":"\u5982\u4f55\u5728 Python Flask \u6846\u67b6\u4e2d\u5b9e\u73b0\u7c7b\u4f3c Laravel \u4e2d\u95f4\u4ef6\u7684\u8bf7\u6c42\u62e6\u622a\u529f\u80fd\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5728 Python Flask \u6846\u67b6\u4e2d\u5b9e\u73b0\u7c7b\u4f3c Laravel \u4e2d\u95f4\u4ef6\u7684\u8bf7\u6c42\u62e6\u622a\u529f\u80fd\uff1f <\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u5728 Python Flask \u6846\u67b6\u4e2d\u5b9e\u73b0\u7c7b\u4f3c Laravel \u4e2d\u95f4\u4ef6\u7684\u8bf7\u6c42\u62e6\u622a\u529f\u80fd\uff1f \u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241116\/1731746018673858e2d310f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5728 python flask \u6846\u67b6\u4e2d\u50cf php laravel \u6846\u67b6\u90a3\u6837\u4ee5\u4e2d\u95f4\u4ef6\u65b9\u5f0f\u62e6\u622a\u8bf7\u6c42<\/strong><\/p>\n<p>\u5728 web \u5f00\u53d1\u4e2d\uff0c\u4e2d\u95f4\u4ef6\u662f\u4e00\u79cd\u5728\u8bf7\u6c42\u5904\u7406\u524d\u6216\u540e\u6267\u884c\u7684\u4e00\u6bb5\u4ee3\u7801\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u9a8c\u8bc1\u6388\u6743\u3001\u65e5\u5fd7\u8bb0\u5f55\u6216\u5176\u4ed6\u9884\u5b9a\u4e49\u4efb\u52a1\u3002<\/p>\n<p><strong>python flask \u4e2d\u7684\u8bf7\u6c42\u62e6\u622a<\/strong><\/p>\n<p>\u5728 python flask \u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u88c5\u9970\u5668\u6765\u5b9e\u73b0\u7c7b\u4f3c php laravel \u6846\u67b6\u4e2d\u4e2d\u95f4\u4ef6\u5bf9\u8bf7\u6c42\u7684\u62e6\u622a\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u60a8\u60f3\u8981\u5b9e\u73b0\u4e00\u4e2a\u4e2d\u95f4\u4ef6\u6765\u9a8c\u8bc1\u8bf7\u6c42\u662f\u5426\u5df2\u901a\u8fc7\u9a8c\u8bc1\uff0c\u5426\u5219\u8fd4\u56de 401 \u9519\u8bef\uff1a<\/p>\n<pre>app = Flask(__name__)\n\n@app.before_request\ndef check_auth():\n    if not is_authenticated():\n        abort(401)<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0ccheck_auth \u88c5\u9970\u5668\u662f\u5728\u6bcf\u6b21\u8bf7\u6c42\u5904\u7406\u524d\u6267\u884c\u7684\u3002\u5b83\u68c0\u67e5 is_authenticated() \u51fd\u6570\uff0c\u786e\u5b9a\u8bf7\u6c42\u662f\u5426\u5df2\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u3002\u5982\u679c\u6ca1\u6709\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5b83\u5c06\u4e2d\u6b62\u8bf7\u6c42\u5e76\u8fd4\u56de 401 \u9519\u8bef\u3002<\/p>\n<p>\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u50cf php laravel \u6846\u67b6\u4e2d\u90a3\u6837\u5728 flask \u6846\u67b6\u4e2d\u5b9e\u73b0\u4e2d\u95f4\u4ef6\u5bf9\u8bf7\u6c42\u7684\u62e6\u622a\u529f\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 Python Flask&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204794","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204794"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204794\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}