{"id":24119,"date":"2024-11-21T10:25:13","date_gmt":"2024-11-21T02:25:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24119\/"},"modified":"2024-11-21T10:25:13","modified_gmt":"2024-11-21T02:25:13","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87webman%e6%a1%86%e6%9e%b6%e5%ae%9e%e7%8e%b0%e5%9c%b0%e7%90%86%e4%bd%8d%e7%bd%ae%e5%ae%9a%e4%bd%8d%e5%92%8c%e5%9c%b0%e5%9b%be%e5%b1%95%e7%a4%ba%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24119\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7Webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\uff1f"},"content":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\uff1f<\/p>\n<p>Webman\u662f\u4e00\u6b3e\u57fa\u4e8ePython\u7684\u5feb\u901f\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u6846\u67b6\u3002\u4f7f\u7528Webman\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5404\u79cd\u529f\u80fd\uff0c\u5305\u62ec\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7Webman\u6846\u67b6\u6765\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u5e76\u9644\u4e0a\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Webman\u6846\u67b6\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Webman\uff1a<\/p>\n<pre>pip install webman<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f00\u59cb\u5f00\u53d1\u6211\u4eec\u7684\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u4e0e\u5730\u56fe\u5c55\u793a\u529f\u80fd\u4e86\u3002<\/p>\n<ol>\n<li>\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u7684API\u6765\u83b7\u53d6\u7528\u6237\u7684\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ee5\u767e\u5ea6\u5730\u56fe\u7684\u5730\u7406\u7f16\u7801API\u4e3a\u4f8b\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684requests\u5e93\u6765\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f\u3002<\/p>\n<pre>import requests\n\ndef get_location(address):\n    url = 'http:\/\/api.map.baidu.com\/geocoding\/v3\/?address={}&amp;amp;output=json&amp;amp;ak=your_api_key'.format(address)\n    try:\n        response = requests.get(url)\n        data = response.json()\n        location = data['result']['location']\n        return location['lng'], location['lat']\n    except Exception as e:\n        print('Error:', e)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2aget_location\u51fd\u6570\u6765\u83b7\u53d6\u6307\u5b9a\u5730\u5740\u7684\u7ecf\u7eac\u5ea6\u4fe1\u606f\u3002\u5176\u4e2d\uff0caddress\u53c2\u6570\u662f\u8981\u67e5\u8be2\u7684\u5730\u5740\uff0cyour_api_key\u662f\u4f60\u5728\u767e\u5ea6\u5730\u56fe\u5f00\u653e\u5e73\u53f0\u7533\u8bf7\u7684API\u5bc6\u94a5\u3002<\/p>\n<ol>\n<li>\u5730\u56fe\u5c55\u793a<\/li>\n<\/ol>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u4e00\u4e2a\u7f51\u9875\u6765\u5c55\u793a\u5730\u56fe\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u767e\u5ea6\u5730\u56fe\u7684JavaScript API\u6765\u521b\u5efa\u5730\u56fe\u5e76\u663e\u793a\u4f4d\u7f6e\u6807\u8bb0\u3002<\/p>\n<p>\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u9759\u6001\u6587\u4ef6\u5939\uff0c\u5e76\u5c06\u767e\u5ea6\u5730\u56fe\u7684JavaScript API\u6587\u4ef6\u653e\u5165\u8be5\u6587\u4ef6\u5939\u4e2d\u3002\u7136\u540e\uff0c\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u4e00\u4e2a\u7f51\u9875\u6765\u5c55\u793a\u5730\u56fe\u3002<\/p>\n<pre>from webman import Webman, render_template\n\napp = Webman()\n\n@app.route('\/')\ndef index():\n    return render_template('index.html')\n\nif __name__ == '__main__':\n    app.run()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3aindex\u7684\u8def\u7531\uff0c\u5b83\u5c06\u4f1a\u6e32\u67d3\u4e00\u4e2a\u540d\u4e3aindex.html\u7684\u6a21\u677f\u6587\u4ef6\u3002<\/p>\n<p>\u5728index.html\u6a21\u677f\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5f15\u5165\u767e\u5ea6\u5730\u56fe\u7684JavaScript API\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a<\/p>\n<p>  \u6807\u7b7e\u6765\u663e\u793a\u5730\u56fe\uff0c\u5982\u4e0b\u6240\u793a\uff1a  <\/p>\n<pre>\n\n\n    &lt;title&gt;\u5730\u56fe\u5c55\u793a&lt;\/title&gt;&lt;script type=\"text\/javascript\" src=\"static\/baidu_map.js\"&gt;&lt;\/script&gt;&lt;div id=\"map\" style=\"width:800px;height:600px;\"&gt;&lt;\/div&gt;\n    &lt;script type=\"text\/javascript\"&gt;\n        \/\/ \u83b7\u53d6\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f\n        var lng = {{ location[0] }};\n        var lat = {{ location[1] }};\n        \n        \/\/ \u521b\u5efa\u5730\u56fe\n        var map = new BMap.Map(\"map\");\n        var point = new BMap.Point(lng, lat);\n        map.centerAndZoom(point, 15);\n        \n        \/\/ \u6dfb\u52a0\u6807\u8bb0\n        var marker = new BMap.Marker(point);\n        map.addOverlay(marker);\n    &lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2a<\/p>\n<p>  \u6807\u7b7e\u6765\u663e\u793a\u5730\u56fe\uff0c\u5e76\u4f7f\u7528\u4e86{{ location[0] }}\u548c{{ location[1] }}\u8fd9\u4e24\u4e2a\u6a21\u677f\u53d8\u91cf\u6765\u83b7\u53d6\u7ecf\u5ea6\u548c\u7eac\u5ea6\u7684\u503c\u3002 <\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u4fee\u6539\u4e4b\u524d\u7684get_location\u51fd\u6570\uff0c\u5c06\u83b7\u53d6\u5230\u7684\u7ecf\u7eac\u5ea6\u4fe1\u606f\u4f20\u7ed9\u6a21\u677f\u53d8\u91cf\uff0c\u5728index\u8def\u7531\u4e2d\u6e32\u67d3\u6a21\u677f\u6587\u4ef6\u3002<\/p>\n<pre>@app.route('\/')\ndef index():\n    address = '\u5317\u4eac\u5e02\u4e2d\u5173\u6751'\n    location = get_location(address)\n    return render_template('index.html', location=location)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5047\u8bbe\u7528\u6237\u8981\u67e5\u8be2\u7684\u5730\u5740\u662f\u5317\u4eac\u5e02\u4e2d\u5173\u6751\uff0c\u7136\u540e\u83b7\u53d6\u4e86\u8be5\u5730\u5740\u7684\u7ecf\u7eac\u5ea6\u4fe1\u606f\uff0c\u5e76\u5c06\u5b83\u4f20\u7ed9\u4e86location\u6a21\u677f\u53d8\u91cf\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u901a\u8fc7Webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\u3002\u901a\u8fc7\u4f7f\u7528Webman\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5f00\u53d1\u5404\u79cd\u529f\u80fd\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6269\u5c55\u80fd\u529b\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5982\u6709\u7591\u95ee\uff0c\u8bf7\u7559\u8a00\u8ba8\u8bba\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7Webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\uff1f\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>\u5982\u4f55\u901a\u8fc7webman\u6846\u67b6\u5b9e\u73b0\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u529f\u80fd\uff1f Webman\u662f\u4e00\u6b3e\u57fa\u4e8ePython\u7684\u5feb\u901f\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u6846\u67b6\u3002\u4f7f\u7528Webman\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5404\u79cd\u529f\u80fd\uff0c\u5305\u62ec\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u548c\u5730\u56fe\u5c55\u793a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7Webman\u6846\u67b6\u6765\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u5e76\u9644\u4e0a\u4ee3\u7801\u793a\u4f8b\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Webman\u6846\u67b6\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Webman\uff1a pip install webman \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f00\u59cb\u5f00\u53d1\u6211\u4eec\u7684\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u4e0e\u5730\u56fe\u5c55\u793a\u529f\u80fd\u4e86\u3002 \u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u5730\u7406\u4f4d\u7f6e\u5b9a\u4f4d\u7684API\u6765\u83b7\u53d6\u7528\u6237\u7684\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ee5\u767e\u5ea6\u5730\u56fe\u7684\u5730\u7406\u7f16\u7801API\u4e3a\u4f8b\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684requests\u5e93\u6765\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f\u3002 import requests def get_location(address): url = &#8216;http:\/\/api.map.baidu.com\/geocoding\/v3\/?address={}&amp;amp;output=json&amp;amp;ak=your_api_key&#8217;.format(address) try: response = requests.get(url) data = response.json() location = data[&#8216;result&#8217;][&#8216;location&#8217;] return location[&#8216;lng&#8217;], location[&#8216;lat&#8217;] except Exception as e: print(&#8216;Error:&#8217;, e) \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e00\u4e2aget_location\u51fd\u6570\u6765\u83b7\u53d6\u6307\u5b9a\u5730\u5740\u7684\u7ecf\u7eac\u5ea6\u4fe1\u606f\u3002\u5176\u4e2d\uff0caddress\u53c2\u6570\u662f\u8981\u67e5\u8be2\u7684\u5730\u5740\uff0cyour_api_key\u662f\u4f60\u5728\u767e\u5ea6\u5730\u56fe\u5f00\u653e\u5e73\u53f0\u7533\u8bf7\u7684API\u5bc6\u94a5\u3002 \u5730\u56fe\u5c55\u793a \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u4e00\u4e2a\u7f51\u9875\u6765\u5c55\u793a\u5730\u56fe\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u767e\u5ea6\u5730\u56fe\u7684JavaScript API\u6765\u521b\u5efa\u5730\u56fe\u5e76\u663e\u793a\u4f4d\u7f6e\u6807\u8bb0\u3002 \u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u9759\u6001\u6587\u4ef6\u5939\uff0c\u5e76\u5c06\u767e\u5ea6\u5730\u56fe\u7684JavaScript API\u6587\u4ef6\u653e\u5165\u8be5\u6587\u4ef6\u5939\u4e2d\u3002\u7136\u540e\uff0c\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u4e00\u4e2a\u7f51\u9875\u6765\u5c55\u793a\u5730\u56fe\u3002 from webman import Webman, render_template app = Webman() @app.route(&#8216;\/&#8217;) def index(): return [&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-24119","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24119","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=24119"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24119\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}