{"id":24380,"date":"2024-11-21T14:42:36","date_gmt":"2024-11-21T06:42:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24380\/"},"modified":"2024-11-21T14:42:36","modified_gmt":"2024-11-21T06:42:36","slug":"webman%ef%bc%9a%e4%b8%80%e4%b8%aa%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84%e5%ae%8c%e7%be%8e%e4%bc%99%e4%bc%b4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24380\/","title":{"rendered":"Webman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169190794459737.jpg\" class=\"aligncenter\" title=\"Webman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34\u63d2\u56fe\" alt=\"Webman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34\u63d2\u56fe\" \/><\/p>\n<p>Webman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34<\/p>\n<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u5f00\u53d1\u5df2\u7ecf\u6210\u4e3a\u4e86\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u9886\u57df\u3002\u5728\u8fd9\u4e2a\u9886\u57df\uff0c\u5f00\u53d1\u8005\u9700\u8981\u638c\u63e1\u591a\u79cd\u6280\u672f\u548c\u5de5\u5177\u6765\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u9760\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u800c\u4f5c\u4e3a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34\uff0cWebman\u63d0\u4f9b\u4e86\u8bb8\u591a\u6709\u7528\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u5f00\u53d1\u8fc7\u7a0b\uff0c\u5e76\u63d0\u9ad8\u4e86\u6548\u7387\u3002<\/p>\n<p>Webman\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u8bed\u8a00\u7684Web\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u7ed3\u5408\u4e86\u8bb8\u591a\u5e38\u7528\u7684\u5de5\u5177\u548c\u5e93\uff0c\u7ed9\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4e00\u7ad9\u5f0f\u7684\u5f00\u53d1\u73af\u5883\u3002\u65e0\u8bba\u662f\u6784\u5efa\u4e00\u4e2a\u5c0f\u578b\u7684\u4e2a\u4eba\u7f51\u7ad9\uff0c\u8fd8\u662f\u5f00\u53d1\u4e00\u4e2a\u5927\u578b\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u7a0b\u5e8f\uff0cWebman\u90fd\u80fd\u6ee1\u8db3\u5f00\u53d1\u8005\u7684\u9700\u6c42\u3002<\/p>\n<p>\u4e0b\u9762\u5c06\u4ecb\u7ecdWebman\u7684\u51e0\u4e2a\u91cd\u8981\u7279\u6027\u548c\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<ol>\n<li>\u8def\u7531\u63a7\u5236<\/li>\n<\/ol>\n<p>Webman\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u8def\u7531\u63a7\u5236\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9a\u4e49URL\u4e0e\u5904\u7406\u51fd\u6570\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>from webman import route, run\n\n@route('\/')\ndef index():\n    return 'Hello, World!'\n\nrun()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6839URL\uff0c\u5f53\u7528\u6237\u8bbf\u95ee\u6839URL\u65f6\uff0c\u5c06\u4f1a\u8c03\u7528index\u51fd\u6570\u5e76\u8fd4\u56de&#8221;Hello, World!&#8221;\u5b57\u7b26\u4e32\u3002<\/p>\n<ol>\n<li>\u6a21\u677f\u5f15\u64ce<\/li>\n<\/ol>\n<p>Webman\u5185\u7f6e\u4e86\u5f3a\u5927\u7684\u6a21\u677f\u5f15\u64ce\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u524d\u7aef\u9875\u9762\u4e2d\u63d2\u5165\u52a8\u6001\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>from webman import route, run, render_template\n\n@route('\/')\ndef index():\n    name = 'John'\n    return render_template('index.html', name=name)\n\nrun()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0crender_template\u51fd\u6570\u5c06\u4f1a\u6e32\u67d3index.html\u6a21\u677f\uff0c\u5e76\u4f20\u9012\u4e00\u4e2a\u540d\u4e3aname\u7684\u53d8\u91cf\u3002\u5728\u6a21\u677f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u82b1\u62ec\u53f7\u8bed\u6cd5\u6765\u63d2\u5165\u53d8\u91cf\u7684\u503c\uff1a<\/p>\n<pre>\n\n\n    &lt;title&gt;\u6b22\u8fce\u9875\u9762&lt;\/title&gt;&lt;h1&gt;\u6b22\u8fce\uff0c{{ name }}!&lt;\/h1&gt;\n\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5f53\u7528\u6237\u8bbf\u95ee\u6839URL\u65f6\uff0c\u5c06\u4f1a\u663e\u793a\u4e00\u4e2a\u6b22\u8fce\u9875\u9762\uff0c\u4e0a\u9762\u4f1a\u663e\u793a&#8221;\u6b22\u8fce\uff0cJohn!&#8221;\u7684\u6587\u672c\u3002<\/p>\n<ol>\n<li>\u6570\u636e\u5e93\u8bbf\u95ee<\/li>\n<\/ol>\n<p>Webman\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\uff0c\u5e76\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u63a5\u53e3\u6765\u64cd\u4f5c\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528MySQL\u6570\u636e\u5e93\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>from webman import route, run, db\n\n@route('\/users')\ndef get_users():\n    conn = db.connect(host='localhost', user='root', password='password', database='mydb')\n    cursor = conn.cursor()\n    cursor.execute('SELECT * FROM users')\n    result = cursor.fetchall()\n    conn.close()\n    return str(result)\n\nrun()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7db.connect\u51fd\u6570\u8fde\u63a5\u5230MySQL\u6570\u636e\u5e93\uff0c\u6267\u884c\u4e00\u4e2a\u67e5\u8be2\u5e76\u5c06\u7ed3\u679c\u8fd4\u56de\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u5e93\uff0c\u5982SQLite\u3001PostgreSQL\u7b49\u3002<\/p>\n<p>Webman\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5176\u4ed6\u529f\u80fd\uff0c\u5982\u6587\u4ef6\u4e0a\u4f20\u3001\u4f1a\u8bdd\u7ba1\u7406\u3001\u8868\u5355\u9a8c\u8bc1\u7b49\uff0c\u90fd\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u8f7b\u677e\u5730\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u603b\u4e4b\uff0cWebman\u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684Web\u5f00\u53d1\u6846\u67b6\uff0c\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u5927\u5927\u7b80\u5316\u4e86\u5f00\u53d1\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u6709\u7ecf\u9a8c\u7684\u5f00\u53d1\u8005\uff0c\u90fd\u53ef\u4ee5\u4ece\u4e2d\u53d7\u76ca\u3002\u5982\u679c\u4f60\u662f\u4e00\u4e2aWeb\u5f00\u53d1\u8005\uff0c\u4e0d\u59a8\u5c1d\u8bd5\u4e00\u4e0bWebman\uff0c\u5b83\u5c06\u6210\u4e3a\u4f60\u4e0d\u53ef\u6216\u7f3a\u7684\u5f00\u53d1\u4f19\u4f34\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fWebman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Webman\uff1a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34 \u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u5f00\u53d1\u5df2\u7ecf\u6210\u4e3a\u4e86\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u9886\u57df\u3002\u5728\u8fd9\u4e2a\u9886\u57df\uff0c\u5f00\u53d1\u8005\u9700\u8981\u638c\u63e1\u591a\u79cd\u6280\u672f\u548c\u5de5\u5177\u6765\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u9760\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u800c\u4f5c\u4e3a\u4e00\u4e2a\u5f00\u53d1\u8005\u7684\u5b8c\u7f8e\u4f19\u4f34\uff0cWebman\u63d0\u4f9b\u4e86\u8bb8\u591a\u6709\u7528\u7684\u529f\u80fd\u548c\u5de5\u5177\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u5f00\u53d1\u8fc7\u7a0b\uff0c\u5e76\u63d0\u9ad8\u4e86\u6548\u7387\u3002 Webman\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u8bed\u8a00\u7684Web\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u7ed3\u5408\u4e86\u8bb8\u591a\u5e38\u7528\u7684\u5de5\u5177\u548c\u5e93\uff0c\u7ed9\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4e00\u7ad9\u5f0f\u7684\u5f00\u53d1\u73af\u5883\u3002\u65e0\u8bba\u662f\u6784\u5efa\u4e00\u4e2a\u5c0f\u578b\u7684\u4e2a\u4eba\u7f51\u7ad9\uff0c\u8fd8\u662f\u5f00\u53d1\u4e00\u4e2a\u5927\u578b\u7684\u4f01\u4e1a\u7ea7\u5e94\u7528\u7a0b\u5e8f\uff0cWebman\u90fd\u80fd\u6ee1\u8db3\u5f00\u53d1\u8005\u7684\u9700\u6c42\u3002 \u4e0b\u9762\u5c06\u4ecb\u7ecdWebman\u7684\u51e0\u4e2a\u91cd\u8981\u7279\u6027\u548c\u793a\u4f8b\u4ee3\u7801\uff1a \u8def\u7531\u63a7\u5236 Webman\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u8def\u7531\u63a7\u5236\u529f\u80fd\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9a\u4e49URL\u4e0e\u5904\u7406\u51fd\u6570\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a from webman import route, run @route(&#8216;\/&#8217;) def index(): return &#8216;Hello, World!&#8217; run() \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6839URL\uff0c\u5f53\u7528\u6237\u8bbf\u95ee\u6839URL\u65f6\uff0c\u5c06\u4f1a\u8c03\u7528index\u51fd\u6570\u5e76\u8fd4\u56de&#8221;Hello, World!&#8221;\u5b57\u7b26\u4e32\u3002 \u6a21\u677f\u5f15\u64ce Webman\u5185\u7f6e\u4e86\u5f3a\u5927\u7684\u6a21\u677f\u5f15\u64ce\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u524d\u7aef\u9875\u9762\u4e2d\u63d2\u5165\u52a8\u6001\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\u7684\u793a\u4f8b\uff1a from webman import route, run, render_template @route(&#8216;\/&#8217;) def index(): name = &#8216;John&#8217; return render_template(&#8216;index.html&#8217;, name=name) run() \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0crender_template\u51fd\u6570\u5c06\u4f1a\u6e32\u67d3index.html\u6a21\u677f\uff0c\u5e76\u4f20\u9012\u4e00\u4e2a\u540d\u4e3aname\u7684\u53d8\u91cf\u3002\u5728\u6a21\u677f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u82b1\u62ec\u53f7\u8bed\u6cd5\u6765\u63d2\u5165\u53d8\u91cf\u7684\u503c\uff1a &lt;title&gt;\u6b22\u8fce\u9875\u9762&lt;\/title&gt;&lt;h1&gt;\u6b22\u8fce\uff0c{{ name }}!&lt;\/h1&gt; \u767b\u5f55\u540e\u590d\u5236 \u5f53\u7528\u6237\u8bbf\u95ee\u6839URL\u65f6\uff0c\u5c06\u4f1a\u663e\u793a\u4e00\u4e2a\u6b22\u8fce\u9875\u9762\uff0c\u4e0a\u9762\u4f1a\u663e\u793a&#8221;\u6b22\u8fce\uff0cJohn!&#8221;\u7684\u6587\u672c\u3002 \u6570\u636e\u5e93\u8bbf\u95ee Webman\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\uff0c\u5e76\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u63a5\u53e3\u6765\u64cd\u4f5c\u6570\u636e\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528MySQL\u6570\u636e\u5e93\u7684\u793a\u4f8b\uff1a from webman import route, run, db @route(&#8216;\/users&#8217;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-24380","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=24380"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24380\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}