{"id":6394,"date":"2021-04-23T22:15:00","date_gmt":"2021-04-23T14:15:00","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6394"},"modified":"2021-04-24T22:16:35","modified_gmt":"2021-04-24T14:16:35","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-08-%e7%af%87-%ef%bd%9c-%e5%a6%82%e4%bd%95%e4%bd%bf","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6394","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 08 \u7bc7 \uff5c \u5982\u4f55\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\u6e32\u67d3\u6570\u636e\uff08\u4e0a\uff09"},"content":{"rendered":"\n<p>\u5f53\u4f60\u5199\u4e86\u9759\u6001\u7684 HTML \u7f51\u9875\u65f6\uff0c\u5b83\u6ca1\u6709\u4efb\u4f55\u4ea4\u4e92\u3002\u66f4\u591a\u7684\uff0c\u5b83\u53ea\u80fd\u4f5c\u4e3a\u4e00\u79cd\u5c55\u793a\uff0c\u800c\u6211\u4eec\u901a\u5e38\u5199\u7684\u7f51\u9875\u7cfb\u7edf\uff0c\u90fd\u662f\u9700\u8981\u6570\u636e\u4ea4\u4e92\u7684\uff0c\u5982\u4f55\u5c06\u9759\u6001\u7684 View \u5c42\uff08\u9759\u6001\u9875\u9762\uff09\u548c\u5728\u4e1a\u52a1\u903b\u8f91\u5c42\u5f97\u5230\u7684\u6570\u636e\u6253\u901a\u5462\uff1f<\/p>\n\n\n\n<p>\u6709\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u5f0f\u5c31\u662f\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 HTML \u4e2d\u5b9a\u4e49\u4e00\u4e9b\u6a21\u677f\u8bed\u8a00\uff08\u53d8\u91cf\uff09\uff0c\u800c\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u5c06\u5f97\u5230\u7684\u53d8\u91cf\u6570\u636e\u4f20\u7ed9\u5b9a\u4e49\u597d\u7684\u6a21\u677f\u8bed\u8a00\uff0c\u8fd9\u6837\u5c31\u80fd\u8ba9\u9759\u6001\u7684\u7f51\u9875\u300c\u52a8\u300d\u8d77\u6765\uff0c\u4e5f\u5c31\u662f\u6a21\u677f\u5f15\u64ce\u6e32\u67d3\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u4eca\u5929\uff0c\u4e3b\u8981\u7ed9\u4f60\u4ecb\u7ecd\u4e00\u4e0b\uff0cFlask \u4e2d\u7684 Jinja2 \u6a21\u677f\u5f15\u64ce\u7684\u4f7f\u7528\uff0c\u4ee5\u53ca\u90a3\u4e9b\u5e38\u7528\u5230\u7684\u6a21\u677f\u8bed\u8a00\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\u6211\u4eec\u4e0a\u4e00\u7bc7\u7684\u6587\u4ef6\u4ee3\u7801\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u6570\u636e\u5e93\u5e76\u4ece\u4e2d\u63d2\u5165\u4e86\u6570\u636e\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 import Flask\nfrom flask_sqlalchemy import SQLAlchemy\nimport config\n\napp = Flask(__name__)\n# \u4f7f\u7528\u914d\u7f6e\napp.config.from_object(config)\n\n# \u5b9e\u4f8b\u5316\u6570\u636e\u5e93\u5bf9\u8c61\ndb = SQLAlchemy(app)\n\n# \u6570\u636e\u6a21\u578b\nclass Fitness(db.Model):\n    __tablename__ = 'fitness'\n\n    id = db.Column(db.Integer, primary_key=True)\n    sport_name = db.Column(db.String(100))\n    calorie = db.Column(db.Float)\n\n<\/pre><\/div>\n\n\n\n<p>\u90a3\u4e48\u73b0\u5728\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u83b7\u53d6\u6570\u636e\u5e93\u4e2d\u7684\u76f8\u5173\u6570\u636e\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u5c55\u793a\u5230\u9996\u9875\u4e2d\uff0c\u5982\u4f55\u64cd\u4f5c\u5462\uff1f<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"271\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-1024x271.png\" alt=\"\" class=\"wp-image-6396\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-1024x271.png 1024w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-300x79.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-768x203.png 768w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-1536x406.png 1536w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1-769x203.png 769w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.27.06-1.png 1764w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>\u6bd4\u5982\u8981\u83b7\u53d6\u7b2c\u4e8c\u6761\u7684\u8fd0\u52a8\u540d\u79f0\uff0c\u5c55\u73b0\u5230\u9996\u9875\u4e0a\uff0c\u53ef\u80fd\u4f60\u4f1a\u8fd9\u6837\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('\/')\ndef index():\n    fitness = Fitness.query.get(2)\n    return fitness.sport_name\n\n<\/pre><\/div>\n\n\n\n<p>\u8fd9\u6837\u4f60\u8bbf\u95ee\u9996\u9875\u7684\u65f6\u5019\u53ef\u4ee5\u5f97\u5230\u7ed3\u679c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"812\" height=\"346\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.33.35.png\" alt=\"\" class=\"wp-image-6397\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.33.35.png 812w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.33.35-300x128.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.33.35-768x327.png 768w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53485.33.35-769x328.png 769w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/figure><\/div>\n\n\n\n<p>\u867d\u7136\u8fd9\u6837\u7b80\u5355\u7c97\u66b4\u53ef\u4ee5\uff0c\u4f46\u662f\u6211\u4eec\u7684\u9875\u9762\u4e0d\u4ec5\u4ec5\u662f\u83b7\u53d6\u8fd9\u4e48\u4e00\u4e2a\u6570\u636e\uff0c\u5e76\u4e14\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u5c55\u793a\u5230\u4e0d\u540c\u7684\u5730\u65b9\u53bb\uff0c\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u6a21\u677f\u8bed\u8a00\u6765\u5b9a\u4e49\u4e86\u3002<\/p>\n\n\n\n<h2>\u6a21\u677f\u53d8\u91cf\u53c2\u6570\u7684\u4f7f\u7528<\/h2>\n\n\n\n<p>\u8fdb\u5165 templates \u76ee\u5f55\uff0c\u521b\u5efa\u4e00\u4e2a index.html \u6a21\u677f\u6587\u4ef6:<\/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&lt;html&gt;\n\n        &lt;head&gt;\n                &lt;title&gt;{{name}}\u5065\u8eab\u8bb0\u5f55&lt;\/title&gt;\n        &lt;\/head&gt;\n\n        &lt;body&gt;\n            \u8fd0\u52a8\u540d\u79f0\uff1a {{sport_name}} \uff0c\u6d88\u8017\u7684\u5361\u8def\u91cc\uff1a{{cal}}\n        &lt;\/body&gt;\n\n&lt;\/html&gt;\n\n\n<\/pre><\/div>\n\n\n\n<p>\u6211\u4eec\u5728\u8fd9\u91cc\u5206\u522b\u5b9a\u4e49\u4e86\u4e09\u4e2a\u53d8\u91cf\uff0cname\uff0csport_name\uff0ccal<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%3D6394\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"634\" height=\"630\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53489.37.23.png\" alt=\"\" class=\"wp-image-6402\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53489.37.23.png 634w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53489.37.23-300x298.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/\u622a\u5c4f2021-04-24-\u4e0b\u53489.37.23-150x150.png 150w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/figure><\/div>\n\n\n\n<p>ok\uff0c\u8fd9\u662f Jinja2 \u6a21\u677f\u5f15\u64ce\u6700\u5e38\u7528\u7684\u4f7f\u7528\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5148\u719f\u6089\u719f\u6089\uff0c\u4e0b\u4e00\u7bc7\u6211\u8fd8\u4f1a\u7ed9\u4f60\u4ecb\u7ecd\u5b83\u7684\u5176\u5b83\u4f60\u9700\u8981\u4e86\u89e3\u4f7f\u7528\u65b9\u5f0f\uff0c\u6bd4\u5982\u6a21\u677f\u4e4b\u95f4\u5982\u4f55\u5f15\u7528\u4ee5\u53ca\u7ee7\u627f\u3002\u5982\u4f55\u4f7f\u7528 Jinja2 \u672c\u8eab\u63d0\u4f9b\u7684\u65b9\u6cd5\u7b49\uff0c\u90a3\u4e48\u6211\u4eec\u4e0b\u4e00\u7bc7\u89c1\uff0cpeace\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u5199\u4e86\u9759\u6001\u7684 HTML \u7f51\u9875\u65f6\uff0c\u5b83\u6ca1\u6709\u4efb\u4f55\u4ea4\u4e92\u3002\u66f4\u591a\u7684\uff0c\u5b83\u53ea\u80fd\u4f5c\u4e3a\u4e00\u79cd\u5c55\u793a\uff0c\u800c\u6211\u4eec\u901a\u5e38\u5199\u7684\u7f51\u9875\u7cfb\u7edf\uff0c\u90fd\u662f\u9700\u8981\u6570\u636e\u4ea4\u4e92\u7684\uff0c\u5982\u4f55\u5c06\u9759\u6001\u7684 View \u5c42\uff08\u9759\u6001\u9875\u9762\uff09\u548c\u5728\u4e1a\u52a1\u903b\u8f91\u5c42\u5f97\u5230\u7684\u6570\u636e\u6253\u901a\u5462\uff1f \u6709\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u5f0f\u5c31\u662f\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 HTML &hellip;<\/p>\n","protected":false},"author":1,"featured_media":6401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6394"}],"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=6394"}],"version-history":[{"count":2,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6394\/revisions"}],"predecessor-version":[{"id":6404,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6394\/revisions\/6404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6401"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}