{"id":2831,"date":"2024-11-10T09:09:21","date_gmt":"2024-11-10T01:09:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2831\/"},"modified":"2024-11-10T09:09:21","modified_gmt":"2024-11-10T01:09:21","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e8%b0%83%e7%94%a8-python-%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2831\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u8c03\u7528 Python \u51fd\u6570\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173088798362140.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u8c03\u7528 Python \u51fd\u6570\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u8c03\u7528 Python \u51fd\u6570\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u8c03\u7528  \u51fd\u6570<\/strong><\/p>\n<p>\u5728 python \u4e2d\u5b9a\u4e49\u51fd\u6570\uff1a<\/p>\n<pre>def a():\n    print('1')<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u8ba9 js \u80fd\u591f\u8c03\u7528 python \u51fd\u6570\uff0c\u9700\u8981\u5c06\u5176\u66b4\u9732\u4e3a web api\uff1a<\/p>\n<p>\u4f7f\u7528 flask \u6846\u67b6\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>from flask import flask\n\napp = flask(__name__)\n\n@app.route('\/a')\ndef call_python_function():\n    a()\n    return 'success'\n\napp.run()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7 js \u8c03\u7528 api\uff1a<\/p>\n<pre>fetch('\/a')\n  .then(response =&gt; response.text())\n  .then(result =&gt; console.log(result));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65f6\uff0cjs \u53ef\u4ee5\u901a\u8fc7\u53d1\u9001 ajax \u8bf7\u6c42\u6765\u8c03\u7528 python \u51fd\u6570 a()\uff0c\u5e76\u663e\u793a\u8fd4\u56de\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u8c03\u7528 Python \u51fd\u6570\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>js \u8c03\u7528 \u51fd\u6570 \u5728 python \u4e2d\u5b9a\u4e49\u51fd\u6570\uff1a def a(): print(&#8216;1&#8217;) \u767b\u5f55\u540e\u590d\u5236 \u8981\u8ba9 js \u80fd\u591f\u8c03\u7528 python \u51fd\u6570\uff0c\u9700\u8981\u5c06\u5176\u66b4\u9732\u4e3a web api\uff1a \u4f7f\u7528 flask \u6846\u67b6\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b from flask import flask app = flask(__name__) @app.route(&#8216;\/a&#8217;) def call_python_function(): a() return &#8216;success&#8217; app.run() \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7 js \u8c03\u7528 api\uff1a fetch(&#8216;\/a&#8217;) .then(response =&gt; response.text()) .then(result =&gt; console.log(result)); \u767b\u5f55\u540e\u590d\u5236 \u6b64\u65f6\uff0cjs \u53ef\u4ee5\u901a\u8fc7\u53d1\u9001 ajax \u8bf7\u6c42\u6765\u8c03\u7528 python \u51fd\u6570 a()\uff0c\u5e76\u663e\u793a\u8fd4\u56de\u7684\u7ed3\u679c\u3002 [&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-2831","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2831","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=2831"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2831\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}