{"id":1046032,"date":"2024-12-31T13:29:35","date_gmt":"2024-12-31T05:29:35","guid":{"rendered":""},"modified":"2024-12-31T13:29:40","modified_gmt":"2024-12-31T05:29:40","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8js%e9%87%8c%e8%b0%83%e7%94%a8python%e6%96%87%e4%bb%b6%e4%b8%8b%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1046032.html","title":{"rendered":"\u5982\u4f55\u5728js\u91cc\u8c03\u7528python\u6587\u4ef6\u4e0b\u8f7d"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/5da14c10-2e6e-439c-92d2-6bbfee85ac6c.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u5728js\u91cc\u8c03\u7528python\u6587\u4ef6\u4e0b\u8f7d\" \/><\/p>\n<p><p> \u5728JS\u91cc\u8c03\u7528Python\u6587\u4ef6\u4e0b\u8f7d\u53ef\u4ee5\u901a\u8fc7<strong>\u4f7f\u7528Flask\u6846\u67b6\u521b\u5efaAPI\u3001\u8c03\u7528API\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d\u3001\u4f7f\u7528AJAX\u8bf7\u6c42\u4e0e\u670d\u52a1\u5668\u7aef\u4ea4\u4e92\u3001\u786e\u4fdd\u5b89\u5168\u6027<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Flask\u6846\u67b6\u521b\u5efaAPI<\/h3>\n<\/p>\n<p><p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Python Web\u6846\u67b6\uff0c\u9002\u5408\u5feb\u901f\u642d\u5efaAPI\u63a5\u53e3\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aFlask\u670d\u52a1\u5668\uff0c\u5e76\u5b9a\u4e49\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u6587\u4ef6\u4e0b\u8f7d\u8bf7\u6c42\u7684API\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5Flask<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Flask\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install Flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u521b\u5efaFlask\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2aPython\u6587\u4ef6\uff08\u5982\uff1aapp.py\uff09\uff0c\u5e76\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, send_from_directory<\/p>\n<p>import os<\/p>\n<p>app = Flask(__name__)<\/p>\n<h2><strong>\u914d\u7f6e\u6587\u4ef6\u4e0b\u8f7d\u76ee\u5f55<\/strong><\/h2>\n<p>DOWNLOAD_DIRECTORY = os.path.join(os.getcwd(), &#39;downloads&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u6587\u4ef6\u4e0b\u8f7dAPI<\/strong><\/h2>\n<p>@app.route(&#39;\/download\/&lt;filename&gt;&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def download_file(filename):<\/p>\n<p>    try:<\/p>\n<p>        return send_from_directory(DOWNLOAD_DIRECTORY, filename, as_attachment=True)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        return &quot;File not found&quot;, 404<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684Flask\u5e94\u7528\uff0c\u5e76\u5b9a\u4e49\u4e86\u4e00\u4e2aAPI\u63a5\u53e3<code>\/download\/&lt;filename&gt;<\/code>\u7528\u4e8e\u5904\u7406\u6587\u4ef6\u4e0b\u8f7d\u8bf7\u6c42\u3002\u4f60\u9700\u8981\u5c06\u8981\u4e0b\u8f7d\u7684\u6587\u4ef6\u653e\u5728<code>downloads<\/code>\u76ee\u5f55\u4e0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u8c03\u7528API\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d<\/h3>\n<\/p>\n<p><p>\u5728\u524d\u7aefJavaScript\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u53d1\u9001AJAX\u8bf7\u6c42\u6765\u8c03\u7528\u4e0a\u8ff0\u5b9a\u4e49\u7684API\u63a5\u53e3\u5e76\u4e0b\u8f7d\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528AJAX\u8bf7\u6c42<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u539f\u751f\u7684JavaScript\u6216jQuery\u6765\u53d1\u9001AJAX\u8bf7\u6c42\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u539f\u751fJavaScript\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-html\">&lt;!DOCTYPE html&gt;<\/p>\n<p>&lt;html lang=&quot;en&quot;&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;meta charset=&quot;UTF-8&quot;&gt;<\/p>\n<p>    &lt;title&gt;Download File&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;button id=&quot;downloadButton&quot;&gt;Download File&lt;\/button&gt;<\/p>\n<p>    &lt;script&gt;<\/p>\n<p>        document.getElementById(&#39;downloadButton&#39;).addEventListener(&#39;click&#39;, function() {<\/p>\n<p>            const filename = &#39;example.txt&#39;;  \/\/ \u8981\u4e0b\u8f7d\u7684\u6587\u4ef6\u540d<\/p>\n<p>            const url = `http:\/\/localhost:5000\/download\/${filename}`;<\/p>\n<p>            fetch(url)<\/p>\n<p>                .then(response =&gt; {<\/p>\n<p>                    if (response.status === 200) {<\/p>\n<p>                        return response.blob();<\/p>\n<p>                    } else {<\/p>\n<p>                        throw new Error(&#39;File not found&#39;);<\/p>\n<p>                    }<\/p>\n<p>                })<\/p>\n<p>                .then(blob =&gt; {<\/p>\n<p>                    const link = document.createElement(&#39;a&#39;);<\/p>\n<p>                    link.href = URL.createObjectURL(blob);<\/p>\n<p>                    link.download = filename;<\/p>\n<p>                    document.body.appendChild(link);<\/p>\n<p>                    link.click();<\/p>\n<p>                    link.remove();<\/p>\n<p>                })<\/p>\n<p>                .catch(error =&gt; {<\/p>\n<p>                    console.error(&#39;Error:&#39;, error);<\/p>\n<p>                });<\/p>\n<p>        });<\/p>\n<p>    &lt;\/script&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u4f1a\u89e6\u53d1\u4e00\u4e2aAJAX\u8bf7\u6c42\u5230Flask\u670d\u52a1\u5668\uff0c\u4ee5\u4e0b\u8f7d\u6307\u5b9a\u7684\u6587\u4ef6\u3002\u4e0b\u8f7d\u6210\u529f\u540e\uff0c\u524d\u7aef\u4f1a\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u7684\u94fe\u63a5\u5e76\u89e6\u53d1\u4e0b\u8f7d\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u786e\u4fdd\u5b89\u5168\u6027<\/h3>\n<\/p>\n<p><p>\u5f53\u6d89\u53ca\u5230\u6587\u4ef6\u4e0b\u8f7d\u65f6\uff0c\u5b89\u5168\u6027\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u65b9\u9762\u3002\u4f60\u9700\u8981\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u624d\u80fd\u4e0b\u8f7d\u6587\u4ef6\uff0c\u5e76\u4e14\u9632\u6b62\u76ee\u5f55\u904d\u5386\u653b\u51fb\u3002<\/p>\n<\/p>\n<p><h4>\u9a8c\u8bc1\u7528\u6237\u6743\u9650<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728Flask\u5e94\u7528\u4e2d\u6dfb\u52a0\u7528\u6237\u8ba4\u8bc1\u673a\u5236\uff0c\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u624d\u80fd\u8bbf\u95ee\u6587\u4ef6\u4e0b\u8f7dAPI\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Flask-Login\u5e93\u5b9e\u73b0\u7528\u6237\u767b\u5f55\u8ba4\u8bc1\u3002<\/p>\n<\/p>\n<p><h4>\u9632\u6b62\u76ee\u5f55\u904d\u5386\u653b\u51fb<\/h4>\n<\/p>\n<p><p>\u5728\u4e0b\u8f7d\u6587\u4ef6\u65f6\uff0c\u8981\u9a8c\u8bc1\u8bf7\u6c42\u7684\u6587\u4ef6\u540d\u662f\u5426\u6709\u6548\uff0c\u907f\u514d\u7528\u6237\u901a\u8fc7\u6784\u9020\u6076\u610f\u8def\u5f84\u6765\u4e0b\u8f7d\u670d\u52a1\u5668\u4e0a\u7684\u4efb\u610f\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, send_from_directory, request, abort<\/p>\n<p>import os<\/p>\n<p>app = Flask(__name__)<\/p>\n<h2><strong>\u914d\u7f6e\u6587\u4ef6\u4e0b\u8f7d\u76ee\u5f55<\/strong><\/h2>\n<p>DOWNLOAD_DIRECTORY = os.path.join(os.getcwd(), &#39;downloads&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u6587\u4ef6\u4e0b\u8f7dAPI<\/strong><\/h2>\n<p>@app.route(&#39;\/download\/&lt;filename&gt;&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def download_file(filename):<\/p>\n<p>    if &#39;..&#39; in filename or filename.startswith(&#39;\/&#39;):<\/p>\n<p>        abort(400, &quot;Invalid filename&quot;)<\/p>\n<p>    try:<\/p>\n<p>        return send_from_directory(DOWNLOAD_DIRECTORY, filename, as_attachment=True)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        return &quot;File not found&quot;, 404<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u901a\u8fc7\u68c0\u67e5\u6587\u4ef6\u540d\u4e2d\u662f\u5426\u5305\u542b<code>..<\/code>\u6216\u4ee5<code>\/<\/code>\u5f00\u5934\u6765\u9632\u6b62\u76ee\u5f55\u904d\u5386\u653b\u51fb\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55<\/h3>\n<\/p>\n<p><h4>\u652f\u6301\u66f4\u591a\u6587\u4ef6\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u6269\u5c55Flask\u5e94\u7528\u4ee5\u652f\u6301\u66f4\u591a\u6587\u4ef6\u7c7b\u578b\u4e0b\u8f7d\u3002\u901a\u8fc7\u4fee\u6539API\u63a5\u53e3\uff0c\u53ef\u4ee5\u652f\u6301\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u5982\u56fe\u7247\u3001\u6587\u6863\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, send_from_directory, request, abort<\/p>\n<p>import os<\/p>\n<p>app = Flask(__name__)<\/p>\n<h2><strong>\u914d\u7f6e\u6587\u4ef6\u4e0b\u8f7d\u76ee\u5f55<\/strong><\/h2>\n<p>DOWNLOAD_DIRECTORY = os.path.join(os.getcwd(), &#39;downloads&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u6587\u4ef6\u4e0b\u8f7dAPI<\/strong><\/h2>\n<p>@app.route(&#39;\/download\/&lt;path:filename&gt;&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def download_file(filename):<\/p>\n<p>    if &#39;..&#39; in filename or filename.startswith(&#39;\/&#39;):<\/p>\n<p>        abort(400, &quot;Invalid filename&quot;)<\/p>\n<p>    try:<\/p>\n<p>        return send_from_directory(DOWNLOAD_DIRECTORY, filename, as_attachment=True)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        return &quot;File not found&quot;, 404<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6dfb\u52a0\u66f4\u591a\u529f\u80fd<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728Flask\u5e94\u7528\u4e2d\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\uff0c\u5982\u65e5\u5fd7\u8bb0\u5f55\u3001\u6587\u4ef6\u4e0b\u8f7d\u7edf\u8ba1\u7b49\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7ba1\u7406\u548c\u76d1\u63a7\u6587\u4ef6\u4e0b\u8f7d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, send_from_directory, request, abort<\/p>\n<p>import os<\/p>\n<p>import logging<\/p>\n<p>app = Flask(__name__)<\/p>\n<h2><strong>\u914d\u7f6e\u6587\u4ef6\u4e0b\u8f7d\u76ee\u5f55<\/strong><\/h2>\n<p>DOWNLOAD_DIRECTORY = os.path.join(os.getcwd(), &#39;downloads&#39;)<\/p>\n<h2><strong>\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/h2>\n<p>logging.basicConfig(filename=&#39;download.log&#39;, level=logging.INFO)<\/p>\n<h2><strong>\u5b9a\u4e49\u6587\u4ef6\u4e0b\u8f7dAPI<\/strong><\/h2>\n<p>@app.route(&#39;\/download\/&lt;path:filename&gt;&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def download_file(filename):<\/p>\n<p>    if &#39;..&#39; in filename or filename.startswith(&#39;\/&#39;):<\/p>\n<p>        abort(400, &quot;Invalid filename&quot;)<\/p>\n<p>    try:<\/p>\n<p>        # \u8bb0\u5f55\u4e0b\u8f7d\u8bf7\u6c42<\/p>\n<p>        logging.info(f&quot;File downloaded: {filename}&quot;)<\/p>\n<p>        return send_from_directory(DOWNLOAD_DIRECTORY, filename, as_attachment=True)<\/p>\n<p>    except FileNotFoundError:<\/p>\n<p>        return &quot;File not found&quot;, 404<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0cFlask\u5e94\u7528\u4f1a\u5c06\u6bcf\u6b21\u6587\u4ef6\u4e0b\u8f7d\u8bf7\u6c42\u8bb0\u5f55\u5230\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u548c\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u5728JavaScript\u4e2d\u8c03\u7528Python\u6587\u4ef6\u4e0b\u8f7d\u7684\u529f\u80fd\u3002<strong>\u4f7f\u7528Flask\u6846\u67b6\u521b\u5efaAPI\u3001\u8c03\u7528API\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d\u3001\u4f7f\u7528AJAX\u8bf7\u6c42\u4e0e\u670d\u52a1\u5668\u7aef\u4ea4\u4e92\u3001\u786e\u4fdd\u5b89\u5168\u6027<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u5173\u952e\u6b65\u9aa4\u3002\u901a\u8fc7\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55\uff0c\u53ef\u4ee5\u4f7f\u8fd9\u4e00\u529f\u80fd\u66f4\u52a0\u5b8c\u5584\u548c\u5b89\u5168\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728JavaScript\u4e2d\u8c03\u7528Python\u811a\u672c\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d\uff1f<\/strong><br \/>\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7AJAX\u8bf7\u6c42\u6216Fetch API\u4e0e\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\uff0c\u8c03\u7528Python\u811a\u672c\u6765\u5904\u7406\u6587\u4ef6\u4e0b\u8f7d\u3002\u901a\u5e38\uff0c\u60a8\u9700\u8981\u5728\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u4e00\u4e2aPython web\u6846\u67b6\uff08\u5982Flask\u6216Django\uff09\uff0c\u5e76\u5c06\u6587\u4ef6\u4e0b\u8f7d\u7684\u8bf7\u6c42\u53d1\u9001\u5230\u76f8\u5e94\u7684\u7aef\u70b9\u3002Python\u811a\u672c\u5c06\u5904\u7406\u8bf7\u6c42\u5e76\u8fd4\u56de\u6587\u4ef6\u4f9b\u4e0b\u8f7d\u3002<\/p>\n<p><strong>\u4f7f\u7528Python Flask\u6846\u67b6\u5b9e\u73b0\u6587\u4ef6\u4e0b\u8f7d\u7684\u57fa\u672c\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u4f7f\u7528Flask\u6846\u67b6\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u6587\u4ef6\u4e0b\u8f7d\u3002\u9996\u5148\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u8def\u7531\u6765\u5904\u7406\u4e0b\u8f7d\u8bf7\u6c42\uff0c\u7136\u540e\u5728\u8def\u7531\u4e2d\u4f7f\u7528<code>send_file<\/code>\u6216<code>send_from_directory<\/code>\u51fd\u6570\u6765\u8fd4\u56de\u6587\u4ef6\u3002\u786e\u4fdd\u5728JavaScript\u4e2d\u4f7f\u7528Fetch API\u6216XMLHttpRequest\u5411\u8be5\u8def\u7531\u53d1\u9001\u8bf7\u6c42\uff0c\u4ee5\u4fbf\u542f\u52a8\u4e0b\u8f7d\u3002<\/p>\n<p><strong>\u5728\u8c03\u7528Python\u811a\u672c\u65f6\uff0c\u5982\u4f55\u5904\u7406\u8de8\u57df\u8bf7\u6c42\u95ee\u9898\uff1f<\/strong><br \/>\u5982\u679cJavaScript\u548cPython\u811a\u672c\u4e0d\u5728\u540c\u4e00\u4e2a\u57df\u540d\u4e0b\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u8de8\u57df\u8d44\u6e90\u5171\u4eab\uff08CORS\uff09\u95ee\u9898\u3002\u53ef\u4ee5\u5728Python\u7684Flask\u6216Django\u4e2d\u914d\u7f6eCORS\uff0c\u5141\u8bb8\u7279\u5b9a\u7684\u57df\u540d\u8fdb\u884c\u8bf7\u6c42\u3002\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528<code>flask-cors<\/code>\u5305\u6216Django\u7684CORS\u4e2d\u95f4\u4ef6\u6765\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u786e\u4fddJavaScript\u80fd\u591f\u6210\u529f\u8c03\u7528Python\u670d\u52a1\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u4e0b\u8f7d\u7684\u6587\u4ef6\u683c\u5f0f\u6b63\u786e\u4e14\u5b89\u5168\uff1f<\/strong><br \/>\u5728Python\u811a\u672c\u4e2d\uff0c\u786e\u4fdd\u5728\u8fd4\u56de\u6587\u4ef6\u65f6\u8bbe\u7f6e\u6b63\u786e\u7684<code>Content-Type<\/code>\uff0c\u4ee5\u4fbf\u6d4f\u89c8\u5668\u80fd\u591f\u8bc6\u522b\u6587\u4ef6\u683c\u5f0f\u3002\u6b64\u5916\uff0c\u5efa\u8bae\u68c0\u67e5\u6587\u4ef6\u7684\u5b89\u5168\u6027\uff0c\u786e\u4fdd\u7528\u6237\u53ea\u80fd\u4e0b\u8f7d\u4ed6\u4eec\u6709\u6743\u9650\u8bbf\u95ee\u7684\u6587\u4ef6\uff0c\u9632\u6b62\u6f5c\u5728\u7684\u5b89\u5168\u6f0f\u6d1e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728JS\u91cc\u8c03\u7528Python\u6587\u4ef6\u4e0b\u8f7d\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Flask\u6846\u67b6\u521b\u5efaAPI\u3001\u8c03\u7528API\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d\u3001\u4f7f\u7528AJAX\u8bf7\u6c42 [&hellip;]","protected":false},"author":3,"featured_media":1046046,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1046032"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1046032"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1046032\/revisions"}],"predecessor-version":[{"id":1046049,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1046032\/revisions\/1046049"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1046046"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1046032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1046032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1046032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}