{"id":6433,"date":"2021-05-16T01:22:00","date_gmt":"2021-05-15T17:22:00","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6433"},"modified":"2021-05-17T01:32:28","modified_gmt":"2021-05-16T17:32:28","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-12-%e7%af%87-%ef%bd%9c-%e5%a6%82%e4%bd%95%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6433","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 12 \u7bc7 \uff5c \u5982\u4f55\u5b9e\u73b0\u7528\u6237\u6ce8\u518c\u767b\u5f55\u529f\u80fd\uff1f"},"content":{"rendered":"\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u5bf9 Flask \u5e38\u7528\u5230\u7684\u57fa\u7840\u64cd\u4f5c\u90fd\u6709\u6240\u4e86\u89e3\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u4f60\u5c31\u53ef\u4ee5\u5f00\u59cb\u5229\u7528\u4f60\u5b66\u5230\u7684\u4e1c\u897f\uff0c\u6765\u4e00\u6b65\u4e00\u6b65\u7684\u5b8c\u5584\u4f60\u7684\u9879\u76ee\uff0c\u6211\u4f1a\u5e26\u4f60\u5b9e\u73b0\u4e00\u4e9b\u4e3b\u8981\u7684\u529f\u80fd\uff0c\u540e\u9762\u4f60\u53ef\u4ee5\u901a\u8fc7\u81ea\u5df1\u7684\u60f3\u6cd5\uff0c\u589e\u52a0\u4f60\u60f3\u5230\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\u54b1\u4eec\u5c31\u6765\u5b9e\u73b0\u7528\u6237\u7684\u6ce8\u518c\u767b\u5f55\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<h2>\u914d\u7f6e\u6570\u636e\u5e93<\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u56de\u987e\u8fd9\u7bc7<a href=\"https:\/\/vip.fxxkpython.com\/?p=6381\">\u5b89\u88c5\u597d\u4f60\u7684\u6570\u636e\u5e93 MYSQL\uff0c\u7136\u540e\u7528 flask-sqlalchemy \u914d\u7f6e\u5b83<\/a>\uff0c\u521b\u5efa\u597d\u4f60\u7684\u6570\u636e\u5e93\u4e4b\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u7684 config.py \u6587\u4ef6\u4e2d\u914d\u7f6e\u4f60\u7684\u6570\u636e\u5e93\u4fe1\u606f\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;}\">USERNAME = 'root'\nPASSWORD = 'root'\nHOST = '127.0.0.1'\nPORT = 3306\nDATABASE = 'mysystem'\n\n# \u6570\u636e\u5e93\u94fe\u63a5 URI\nDB_URI = 'mysql+mysqldb:\/\/{}:{}@{}:{}\/{}'.format(USERNAME, PASSWORD, HOST, PORT, DATABASE)\n\nSQLALCHEMY_DATABASE_URI = DB_URI\nSQLALCHEMY_TRACK_MODIFICATIONS = True<\/pre><\/div>\n\n\n\n<p>\u914d\u7f6e\u597d\u4e86\u4e4b\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728 _<em>init_<\/em>.py \u4e2d\u4f7f\u7528\u914d\u7f6e\uff0c\u4ee5\u53ca\u5bfc\u5165\u76f8\u5173\u7684\u5e93\uff0c\u505a\u4e00\u4e9b\u521d\u59cb\u5316\u7684\u64cd\u4f5c\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;}\">from flask import Flask\nfrom flask_sqlalchemy import SQLAlchemy\n\n\napp = Flask('mysystem')\napp.secret_key = 'mysystem'\n\n# \u4f7f\u7528\u914d\u7f6e\napp.config.from_pyfile('config.py')\n\n# \u5b9e\u4f8b\u5316\u6570\u636e\u5e93\u5bf9\u8c61\ndb = SQLAlchemy(app)\n\nfrom mysystem import commands # \u81ea\u5df1\u521b\u5efa\u7684 commands.py \u6587\u4ef6<\/pre><\/div>\n\n\n\n<h2>\u7528\u6237\u6a21\u578b\u7684\u521b\u5efa<\/h2>\n\n\n\n<p>\u7528\u4e86 db \u5bf9\u8c61\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u521b\u5efa\u7528\u6237\u6a21\u578b\u4e86\uff0c\u7528\u6237\u7684\u6570\u636e\u5e93\u9700\u8981\u5b9a\u4e49\u7528\u6237\u7684 ID\uff0c\u7528\u6237\u540d\u79f0\uff0c\u7528\u6237\u5bc6\u7801\u3002<\/p>\n\n\n\n<p>\u5728 models.py \u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u7c7b\u6765\u751f\u6210\u7528\u6237\u6570\u636e\u8868\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;}\">from mysystem import db\n\nclass User(db.Model):\n    __tablename__ = 'my_user'\n    id = db.Column(db.Integer, primary_key=True)\n    username = db.Column(db.String(30), nullable=False)\n    admin_password = db.Column(db.String(120), nullable=False)<\/pre><\/div>\n\n\n\n<h2>\u7528\u6237\u540d\u5bc6\u7801\u7684\u521b\u5efa<\/h2>\n\n\n\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u4e0d\u4f1a\u5b58\u50a8\u660e\u6587\u5bc6\u7801\uff0c\u56e0\u4e3a\u8fd9\u6837\u505a\u4e0d\u5b89\u5168\uff0c\u5bc6\u7801\u7684\u5b58\u50a8\u5e94\u8be5\u662f\u901a\u8fc7\u52a0\u5bc6\u751f\u6210\u5bc6\u94a5\uff0c\u7136\u540e\u624d\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<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%3D6433\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u8fd0\u884c\u4e00\u4e0b\u547d\u4ee4 flask login\uff1a<\/p>\n\n\n\n<p>\u5f53\u5bc6\u7801\u8f93\u5165\u7684\u4e0d\u662f admin \u65f6\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\nUsername: admin\nPassword: \n\u7528\u6237\u540d\u6216\u5bc6\u7801\u4e0d\u6b63\u786e\n\n<\/pre><\/div>\n\n\n\n<p>\u5f53\u5bc6\u7801\u8f93\u5165\u7684\u662f admin \u65f6\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;}\">\nUsername: admin\nPassword: \n\u767b\u5f55\u6210\u529f\n<\/pre><\/div>\n\n\n\n<p>\u8fd9\u6837\u7684\u5b9e\u73b0\u65b9\u5f0f\u5c31\u76f8\u5bf9\u5b89\u5168\u5f88\u591a\uff0c\u5c3d\u7ba1\u6570\u636e\u5e93\u88ab\u4eba\u53d1\u73b0\uff0c\u4ed6\u4e5f\u65e0\u6cd5\u77e5\u9053\u7528\u6237\u7684\u5177\u4f53\u5bc6\u7801\u3002<\/p>\n\n\n\n<p>ok\uff0c\u4ee5\u4e0a\u5c31\u662f\u4eca\u5929\u7ed9\u4f60\u5e26\u6765\u7684\u5206\u4eab\uff0c\u7528\u6237\u767b\u5f55\u5b9e\u73b0\u601d\u8def\u4f60\u5df2\u7ecf\u77e5\u9053\u4e86\uff0c\u4e0b\u4e00\u6b65\u4f60\u77e5\u9053\u5982\u4f55\u628a\u8fd9\u4e2a\u6d41\u7a0b\u6e32\u67d3\u5230\u7f51\u9875\u53bb\u4e48\uff1f\u4f60\u53ef\u4ee5\u5148\u8bd5\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u5230\u8fd9\u91cc\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u5bf9 Flask \u5e38\u7528\u5230\u7684\u57fa\u7840\u64cd\u4f5c\u90fd\u6709\u6240\u4e86\u89e3\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u4f60\u5c31\u53ef\u4ee5\u5f00\u59cb\u5229\u7528\u4f60\u5b66\u5230\u7684\u4e1c\u897f\uff0c\u6765\u4e00\u6b65\u4e00\u6b65\u7684\u5b8c\u5584\u4f60\u7684\u9879\u76ee\uff0c\u6211\u4f1a\u5e26\u4f60\u5b9e\u73b0\u4e00\u4e9b\u4e3b\u8981\u7684\u529f\u80fd\uff0c\u540e\u9762\u4f60\u53ef\u4ee5\u901a\u8fc7\u81ea\u5df1\u7684\u60f3\u6cd5\uff0c\u589e\u52a0\u4f60\u60f3\u5230\u7684\u529f\u80fd\u3002 \u4eca\u5929\u54b1\u4eec\u5c31\u6765\u5b9e\u73b0\u7528\u6237\u7684\u6ce8\u518c\u767b\u5f55\u7684\u529f\u80fd\u3002 \u914d\u7f6e\u6570&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6435,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[549,594,592,593],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6433"}],"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=6433"}],"version-history":[{"count":1,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6433\/revisions"}],"predecessor-version":[{"id":6436,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6433\/revisions\/6436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6435"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}