{"id":6547,"date":"2021-08-01T02:21:00","date_gmt":"2021-07-31T18:21:00","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6547"},"modified":"2021-08-03T02:23:02","modified_gmt":"2021-08-02T18:23:02","slug":"%e4%bd%bf%e7%94%a8-python-%e4%bb%8e-0-%e5%bc%80%e5%8f%91%e5%b1%9e%e4%ba%8e%e4%bd%a0%e7%9a%84%e4%b8%aa%e4%ba%ba%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f-20-%e7%af%87-%ef%bd%9c-%e7%99%bb%e5%bd%95%e5%8a%9f","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6547","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 20 \u7bc7 \uff5c \u767b\u5f55\u529f\u80fd\u7684\u4f18\u5316"},"content":{"rendered":"\n<p>\u6211\u4eec\u4e4b\u524d\u7684\u767b\u5f55\u529f\u80fd\u4f7f\u7528\u7684\u662f session \u4f1a\u8bdd\uff0c\u8fd9\u6709\u4e00\u5b9a\u7684\u5c40\u9650\uff0c\u5e76\u4e14\u4e0d\u597d\u7ba1\u7406\uff0c\u6709\u4e9b\u8bf7\u6c42\u6211\u4eec\u8fd8\u9700\u8981\u8ba4\u8bc1\u7528\u6237\u767b\u5f55\u4e86\u624d\u53ef\u4ee5\u8bbf\u95ee\uff0c\u6240\u4ee5\uff0c\u4eca\u5929\u5c0f\u5e05b\u8981\u8ddf\u4f60\u8bb2\u8bb2\uff0c\u5982\u4f55\u4f18\u5316\u597d\u4f60\u7684\u767b\u5f55\u529f\u80fd\u3002<\/p>\n\n\n\n<h2>flask-login<\/h2>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 flask-login \u63d2\u4ef6\u6765\u5b9e\u73b0\uff0c\u8fd9\u4e2a\u63d2\u4ef6\u63d0\u4f9b\u4e86\u7528\u6237\u4f1a\u8bdd\u7ba1\u7406\u65b9\u6cd5\uff0c\u6bd4\u5982\u767b\u5f55\uff0c\u767b\u51fa\uff0c\u8bb0\u4f4f\u7528\u6237\u7b49\u4efb\u52a1\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u5728\u81ea\u5df1\u7684\u7cfb\u7edf\u5199\u4e00\u4e9b\u65b9\u6cd5\u548c\u5b83\u7ed3\u5408\u4f7f\u7528\uff0c\u6548\u679c\u6760\u6760\u6ef4\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u9996\u5148\u5b89\u88c5\u4e00\u6ce2\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>pipenv install flask-login<\/p><\/blockquote>\n\n\n\n<p>\u540c\u6837\u7684\uff0c\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u5728\u521d\u59cb\u5316\u6587\u4ef6\u4e2d\u83b7\u53d6\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">\nlogin_manager = LoginManager(app)\nlogin_manager.init_app(app)\n<\/pre><\/div>\n\n\n\n<p>\u52a0\u8f7d\u5f53\u524d\u7528\u6237\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">\n@login_manager.user_loader\ndef load_user(user_id):\n    user = User.query.get(int(user_id))\n    return user\n<\/pre><\/div>\n\n\n\n<h2>model \u4e2d\u7684\u7ee7\u627f<\/h2>\n\n\n\n<p>\u73b0\u5728\u53ef\u4ee5\u5728\u7528\u6237\u6a21\u578b\u4e2d\u7ee7\u627f flask_login \u6765\u5b9e\u73b0\u76f8\u5173\u7684\u65b9\u6cd5\uff0c\u5728 user \u7684 model \u4e2d\uff0c\u5bfc\u5165 userMixin\uff0c\u7136\u540e\u7ee7\u627f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">\nfrom flask_login import UserMixin\n\nclass User(db.Model, UserMixin):\n    __tablename__ = 'my_user'\n    id = db.Column(db.Integer, primary_key=True)\n    username = db.Column(db.String(30), nullable=False)\n    ...\n<\/pre><\/div>\n\n\n\n<h2>\u767b\u5f55<\/h2>\n\n\n\n<p>\u90a3\u4e48\u73b0\u5728\uff0c\u7528\u6237\u7684\u767b\u5f55\u5c31\u53ef\u4ee5\u8fd9\u6837\u64cd\u4f5c\u4e86\uff1a<div style=\"text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;\">\u672c\u6587\u9690\u85cf\u5185\u5bb9 <a href=\"https:\/\/vip.fxxkpython.com\/wp-login.php?redirect_to=https%3A%2F%2Fvip.fxxkpython.com%2F%3Fp%3D6547\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u5728\u4f60\u7684\u7f51\u7ad9\u4e2d\uff0c\u6709\u4e9b\u8bf7\u6c42\u662f\u9700\u8981\u7528\u6237\u767b\u5f55\u4e86\u624d\u80fd\u8bbf\u95ee\u7684\uff0c\u600e\u4e48\u529e\u5462\uff1f<\/p>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528 flask-login \u7684 login_required \u88c5\u9970\u5668\u6765\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u73b0\u5728\uff0c\u7528\u6237\u5728\u6ca1\u6709\u767b\u5f55\u7684\u60c5\u51b5\u4e0b\uff0c\u662f\u65e0\u6cd5\u8bbf\u95ee\u4efb\u52a1\u5217\u8868\u6570\u636e\u7684\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u5728\u8fd9\u4e2a\u8def\u7531\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u88c5\u9970\u5668\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">\n@app.route('\/todolist\/&lt;int:is_done&gt;\/', methods=['GET', 'POST'])\n@login_required\ndef todolist(is_done):\n\t...\n<\/pre><\/div>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u4e2a\u65f6\u5019\uff0c\u5f53\u7528\u6237\u6ca1\u6709\u767b\u5f55\uff0c\u8bbf\u95ee\u8fd9\u4e2a\u8bf7\u6c42\u5c31\u4f1a\u51fa\u73b0 401 \u9519\u8bef\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"171\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-1024x171.png\" alt=\"\" class=\"wp-image-6549\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-1024x171.png 1024w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-300x50.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-768x129.png 768w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-1536x257.png 1536w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06-769x129.png 769w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/08\/\u622a\u5c4f2021-08-03-\u4e0a\u53482.06.06.png 1720w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>OK\uff0c\u4ee5\u4e0a\u5c31\u662f\u5173\u4e8e flask \u767b\u5f55\u7684\u4f18\u5316\u4f7f\u7528\uff0c\u4f60\u5b66\u4f1a\u4e86\u5417\uff1f<\/p>\n\n\n\n<p>\u6211\u4eec\u4e0b\u56de\u89c1\uff0cpeace\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u4e4b\u524d\u7684\u767b\u5f55\u529f\u80fd\u4f7f\u7528\u7684\u662f session \u4f1a\u8bdd\uff0c\u8fd9\u6709\u4e00\u5b9a\u7684\u5c40\u9650\uff0c\u5e76\u4e14\u4e0d\u597d\u7ba1\u7406\uff0c\u6709\u4e9b\u8bf7\u6c42\u6211\u4eec\u8fd8\u9700\u8981\u8ba4\u8bc1\u7528\u6237\u767b\u5f55\u4e86\u624d\u53ef\u4ee5\u8bbf\u95ee\uff0c\u6240\u4ee5\uff0c\u4eca\u5929\u5c0f\u5e05b\u8981\u8ddf\u4f60\u8bb2\u8bb2\uff0c\u5982\u4f55\u4f18\u5316\u597d\u4f60\u7684\u767b\u5f55\u529f\u80fd\u3002 flask-login \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 flask-login \u63d2\u4ef6\u6765\u5b9e\u73b0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6548,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[611,612],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6547"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6547"}],"version-history":[{"count":2,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6547\/revisions"}],"predecessor-version":[{"id":6551,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6547\/revisions\/6551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6548"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}