{"id":24347,"date":"2024-11-21T16:02:32","date_gmt":"2024-11-21T08:02:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24347\/"},"modified":"2024-11-21T16:02:32","modified_gmt":"2024-11-21T08:02:32","slug":"%e6%8e%a2%e7%b4%a2webman%e6%8a%80%e6%9c%af%e5%9c%a8%e6%99%ba%e8%83%bd%e5%ae%b6%e5%b1%85%e9%a2%86%e5%9f%9f%e7%9a%84%e5%89%8d%e6%99%af%e4%b8%8e%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24347\/","title":{"rendered":"\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169188634628118.jpg\" class=\"aligncenter\" title=\"\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528\u63d2\u56fe\" alt=\"\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528\u63d2\u56fe\" \/><\/p>\n<p>\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528<\/p>\n<p>\u667a\u80fd\u5bb6\u5c45\u6280\u672f\u7684\u5feb\u901f\u53d1\u5c55\u4e0e\u666e\u53ca\uff0c\u6b63\u6539\u53d8\u7740\u6211\u4eec\u751f\u6d3b\u7684\u65b9\u65b9\u9762\u9762\u3002\u8d8a\u6765\u8d8a\u591a\u7684\u5bb6\u5ead\u5f00\u59cb\u5b89\u88c5\u667a\u80fd\u8bbe\u5907\uff0c\u5b9e\u73b0\u5bb6\u5c45\u81ea\u52a8\u5316\u3001\u8fdc\u7a0b\u63a7\u5236\u7b49\u529f\u80fd\uff0c\u63d0\u5347\u4e86\u751f\u6d3b\u7684\u4fbf\u6377\u6027\u548c\u8212\u9002\u5ea6\u3002\u5728\u8fd9\u4e00\u80cc\u666f\u4e0b\uff0cWebMan\u6280\u672f\u5e94\u7528\u9010\u6e10\u6210\u4e3a\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u70ed\u95e8\u8bdd\u9898\uff0c\u4e3a\u6211\u4eec\u5e26\u6765\u4e86\u66f4\u52a0\u4fbf\u6377\u3001\u7075\u6d3b\u7684\u667a\u80fd\u5bb6\u5c45\u4f53\u9a8c\u3002<\/p>\n<p>WebMan\u6280\u672f\uff0c\u5373\u57fa\u4e8eWeb\u7684\u8bbe\u5907\u7ba1\u7406\u6280\u672f\uff0c\u901a\u8fc7Web\u6d4f\u89c8\u5668\u8bbf\u95ee\u548c\u63a7\u5236\u667a\u80fd\u8bbe\u5907\uff0c\u5b9e\u73b0\u8bbe\u5907\u7684\u72b6\u6001\u76d1\u6d4b\u3001\u53c2\u6570\u8bbe\u7f6e\u4ee5\u53ca\u64cd\u4f5c\u63a7\u5236\u7b49\u529f\u80fd\u3002\u76f8\u6bd4\u4f20\u7edf\u7684\u5e94\u7528\u5f00\u53d1\u65b9\u5f0f\uff0cWebMan\u6280\u672f\u4e0d\u9700\u8981\u5355\u72ec\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ea\u9700\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u3002<\/p>\n<p>\u9996\u5148\uff0cWebMan\u6280\u672f\u5e26\u6765\u4e86\u667a\u80fd\u5bb6\u5c45\u8bbe\u5907\u7684\u96c6\u4e2d\u7ba1\u7406\u3002\u5728\u4f20\u7edf\u7684\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u9700\u8981\u5b89\u88c5\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bcf\u4e2a\u8bbe\u5907\u5bf9\u5e94\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u7ed9\u7528\u6237\u5e26\u6765\u4e86\u4e0d\u4fbf\u3002\u800c\u4f7f\u7528WebMan\u6280\u672f\uff0c\u7528\u6237\u53ea\u9700\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u8bbe\u5907\u7684IP\u5730\u5740\uff0c\u5c31\u80fd\u591f\u8bbf\u95ee\u548c\u7ba1\u7406\u6240\u6709\u7684\u667a\u80fd\u8bbe\u5907\u3002\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\uff0c\u800c\u4e14\u53ef\u4ee5\u51cf\u5c11\u624b\u673a\u5b58\u50a8\u7a7a\u95f4\u7684\u5360\u7528\u3002<\/p>\n<p>\u5176\u6b21\uff0cWebMan\u6280\u672f\u63d0\u4f9b\u4e86\u8fdc\u7a0b\u63a7\u5236\u7684\u529f\u80fd\u3002\u4f7f\u7528\u4f20\u7edf\u7684\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\uff0c\u7528\u6237\u53ea\u80fd\u5728\u5bb6\u91cc\u624d\u80fd\u63a7\u5236\u8bbe\u5907\uff0c\u4e00\u65e6\u79bb\u5f00\u5bb6\u5c31\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u901a\u8fc7WebMan\u6280\u672f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u901a\u8fc7\u4e92\u8054\u7f51\u8bbf\u95ee\u8bbe\u5907\uff0c\u5e76\u8fdb\u884c\u64cd\u4f5c\u63a7\u5236\u3002\u6bd4\u5982\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4e0a\u73ed\u7684\u8def\u4e0a\u63d0\u524d\u6253\u5f00\u5bb6\u91cc\u7684\u7a7a\u8c03\uff0c\u56de\u5230\u5bb6\u540e\u5c31\u80fd\u611f\u53d7\u5230\u51c9\u723d\u7684\u73af\u5883\u3002\u8fd9\u79cd\u8fdc\u7a0b\u63a7\u5236\u7684\u7075\u6d3b\u6027\u4e3a\u7528\u6237\u5e26\u6765\u4e86\u66f4\u52a0\u4fbf\u6377\u7684\u4f53\u9a8c\u3002<\/p>\n<p>\u53e6\u5916\uff0cWebMan\u6280\u672f\u8fd8\u80fd\u591f\u5b9e\u73b0\u8bbe\u5907\u7684\u72b6\u6001\u76d1\u6d4b\u548c\u53c2\u6570\u8bbe\u7f6e\u3002\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u8bbe\u5907\u7684\u7ba1\u7406\u754c\u9762\uff0c\u7528\u6237\u53ef\u4ee5\u968f\u65f6\u67e5\u770b\u8bbe\u5907\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u6bd4\u5982\u6e29\u5ea6\u3001\u6e7f\u5ea6\u7b49\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u8bbe\u7f6e\u8bbe\u5907\u7684\u53c2\u6570\uff0c\u5982\u5b9a\u65f6\u5f00\u5173\u673a\u3001\u6a21\u5f0f\u9009\u62e9\u7b49\u3002\u8fd9\u79cd\u4e2a\u6027\u5316\u7684\u8bbe\u5907\u7ba1\u7406\u529f\u80fd\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7528\u6237\u7684\u9700\u6c42\u3002<\/p>\n<p>\u4e0b\u9762\uff0c\u6211\u6765\u4ecb\u7ecd\u4e00\u4e2a\u4f7f\u7528WebMan\u6280\u672f\u7684\u667a\u80fd\u5bb6\u5c45\u5b9e\u4f8b\uff0c\u5e76\u6f14\u793a\u4e00\u4e0b\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\uff0c\u5305\u62ec\u4e00\u4e2a\u6e29\u5ea6\u4f20\u611f\u5668\u548c\u4e00\u4e2a\u706f\u5149\u63a7\u5236\u5668\u3002\u6e29\u5ea6\u4f20\u611f\u5668\u8d1f\u8d23\u76d1\u6d4b\u623f\u95f4\u7684\u6e29\u5ea6\uff0c\u800c\u706f\u5149\u63a7\u5236\u5668\u53ef\u4ee5\u63a7\u5236\u623f\u95f4\u7684\u706f\u5149\u5f00\u5173\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u521b\u5efa\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u7528\u4e8e\u63d0\u4f9b\u8bbe\u5907\u7684\u7ba1\u7406\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684Flask\u6846\u67b6\u6765\u642d\u5efa\u7b80\u5355\u7684\u670d\u52a1\u5668\u3002<\/p>\n<pre>from flask import Flask, render_template\n\napp = Flask(__name__)\n\n@app.route('\/')\ndef index():\n    return render_template('index.html')\n\n@app.route('\/api\/temperature')\ndef get_temperature():\n    temperature = 25.5 # \u4ece\u6e29\u5ea6\u4f20\u611f\u5668\u83b7\u53d6\u5b9e\u9645\u6e29\u5ea6\n    return str(temperature)\n\n@app.route('\/api\/light', methods=['GET', 'POST'])\ndef control_light():\n    if request.method == 'POST':\n        # \u4ece\u8bf7\u6c42\u4e2d\u83b7\u53d6\u706f\u5149\u72b6\u6001\n        status = request.form['status']\n        # \u5c06\u706f\u5149\u72b6\u6001\u4f20\u8f93\u7ed9\u706f\u5149\u63a7\u5236\u5668\uff0c\u5b9e\u73b0\u706f\u5149\u5f00\u5173\u63a7\u5236\n    else:\n        # \u4ece\u706f\u5149\u63a7\u5236\u5668\u83b7\u53d6\u5f53\u524d\u706f\u5149\u72b6\u6001\n        status = 'on'\n    return status\n\nif __name__ == '__main__':\n    app.run(debug=True)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u5b9a\u4e49\u4e86\u4e09\u4e2a\u8def\u7531\uff0c\u5206\u522b\u7528\u4e8e\u4e3b\u9875\u3001\u6e29\u5ea6\u83b7\u53d6\u548c\u706f\u5149\u63a7\u5236\u3002\u6e29\u5ea6\u83b7\u53d6\u7684\u63a5\u53e3\u8fd4\u56de\u5b9e\u9645\u6e29\u5ea6\u503c\uff0c\u706f\u5149\u63a7\u5236\u7684\u63a5\u53e3\u53ef\u4ee5\u6839\u636e\u8bf7\u6c42\u8fdb\u884c\u706f\u5149\u5f00\u5173\u63a7\u5236\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u4e3b\u9875\uff0c\u5c55\u793a\u8bbe\u5907\u7684\u72b6\u6001\u548c\u63a7\u5236\u754c\u9762\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528HTML\u548cJavaScript\u6765\u5b9e\u73b0\u3002<\/p>\n<pre>\n\n\n    &lt;meta charset=\"UTF-8\"&gt;&lt;title&gt;\u667a\u80fd\u5bb6\u5c45&lt;\/title&gt;&lt;h1&gt;\u667a\u80fd\u5bb6\u5c45&lt;\/h1&gt;\n    &lt;div id=\"temperature\"&gt;\n        &lt;h2&gt;\u5f53\u524d\u6e29\u5ea6\uff1a--&lt;\/h2&gt;\n    &lt;\/div&gt;\n    &lt;div id=\"light\"&gt;\n        &lt;h2&gt;\u706f\u5149\u72b6\u6001\uff1a--&lt;\/h2&gt;\n        &lt;button id=\"on\"&gt;\u5f00\u706f&lt;\/button&gt;\n        &lt;button id=\"off\"&gt;\u5173\u706f&lt;\/button&gt;\n    &lt;\/div&gt;\n\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.6.0.min.js\"&gt;&lt;\/script&gt;&lt;script&gt;\n        $(document).ready(function() {\n            \/\/ \u83b7\u53d6\u6e29\u5ea6\n            $.get('\/api\/temperature', function(data) {\n                $('#temperature h2').text('\u5f53\u524d\u6e29\u5ea6\uff1a' + data);\n            });\n\n            \/\/ \u63a7\u5236\u706f\u5149\n            $('#on').click(function() {\n                $.post('\/api\/light', { status: 'on' }, function(data) {\n                    $('#light h2').text('\u706f\u5149\u72b6\u6001\uff1a' + data);\n                });\n            });\n\n            $('#off').click(function() {\n                $.post('\/api\/light', { status: 'off' }, function(data) {\n                    $('#light h2').text('\u706f\u5149\u72b6\u6001\uff1a' + data);\n                });\n            });\n        });\n    &lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4f7f\u7528jQuery\u5e93\u5b9e\u73b0\u4e86\u6e29\u5ea6\u548c\u706f\u5149\u7684\u83b7\u53d6\u4e0e\u63a7\u5236\u3002\u901a\u8fc7\u8c03\u7528\u670d\u52a1\u5668\u7684\u63a5\u53e3\u83b7\u53d6\u6570\u636e\u5e76\u66f4\u65b0\u9875\u9762\u5185\u5bb9\uff0c\u5b9e\u73b0\u4e86\u667a\u80fd\u5bb6\u5c45\u8bbe\u5907\u7684\u76d1\u6d4b\u4e0e\u63a7\u5236\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0cWebMan\u6280\u672f\u4e3a\u667a\u80fd\u5bb6\u5c45\u7684\u53d1\u5c55\u63d0\u4f9b\u4e86\u66f4\u52a0\u7075\u6d3b\u3001\u4fbf\u6377\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u4f7f\u5f97\u667a\u80fd\u8bbe\u5907\u7684\u7ba1\u7406\u4e0e\u63a7\u5236\u66f4\u52a0\u96c6\u4e2d\u5316\u3001\u8fdc\u7a0b\u5316\uff0c\u5e76\u4e14\u5b9e\u73b0\u4e86\u8bbe\u5907\u72b6\u6001\u7684\u76d1\u6d4b\u548c\u53c2\u6570\u7684\u8bbe\u7f6e\u3002\u672a\u6765\uff0c\u968f\u7740Web\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cWebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u5e94\u7528\u5c06\u4f1a\u8d8a\u6765\u8d8a\u5e7f\u6cdb\u3002\u6211\u4eec\u53ef\u4ee5\u671f\u5f85\uff0c\u901a\u8fc7WebMan\u6280\u672f\uff0c\u667a\u80fd\u5bb6\u5c45\u5c06\u4e3a\u6211\u4eec\u521b\u9020\u66f4\u52a0\u667a\u80fd\u3001\u4fbf\u6377\u7684\u751f\u6d3b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528\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>\u63a2\u7d22WebMan\u6280\u672f\u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u524d\u666f\u4e0e\u5e94\u7528 \u667a\u80fd\u5bb6\u5c45\u6280\u672f\u7684\u5feb\u901f\u53d1\u5c55\u4e0e\u666e\u53ca\uff0c\u6b63\u6539\u53d8\u7740\u6211\u4eec\u751f\u6d3b\u7684\u65b9\u65b9\u9762\u9762\u3002\u8d8a\u6765\u8d8a\u591a\u7684\u5bb6\u5ead\u5f00\u59cb\u5b89\u88c5\u667a\u80fd\u8bbe\u5907\uff0c\u5b9e\u73b0\u5bb6\u5c45\u81ea\u52a8\u5316\u3001\u8fdc\u7a0b\u63a7\u5236\u7b49\u529f\u80fd\uff0c\u63d0\u5347\u4e86\u751f\u6d3b\u7684\u4fbf\u6377\u6027\u548c\u8212\u9002\u5ea6\u3002\u5728\u8fd9\u4e00\u80cc\u666f\u4e0b\uff0cWebMan\u6280\u672f\u5e94\u7528\u9010\u6e10\u6210\u4e3a\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u7684\u70ed\u95e8\u8bdd\u9898\uff0c\u4e3a\u6211\u4eec\u5e26\u6765\u4e86\u66f4\u52a0\u4fbf\u6377\u3001\u7075\u6d3b\u7684\u667a\u80fd\u5bb6\u5c45\u4f53\u9a8c\u3002 WebMan\u6280\u672f\uff0c\u5373\u57fa\u4e8eWeb\u7684\u8bbe\u5907\u7ba1\u7406\u6280\u672f\uff0c\u901a\u8fc7Web\u6d4f\u89c8\u5668\u8bbf\u95ee\u548c\u63a7\u5236\u667a\u80fd\u8bbe\u5907\uff0c\u5b9e\u73b0\u8bbe\u5907\u7684\u72b6\u6001\u76d1\u6d4b\u3001\u53c2\u6570\u8bbe\u7f6e\u4ee5\u53ca\u64cd\u4f5c\u63a7\u5236\u7b49\u529f\u80fd\u3002\u76f8\u6bd4\u4f20\u7edf\u7684\u5e94\u7528\u5f00\u53d1\u65b9\u5f0f\uff0cWebMan\u6280\u672f\u4e0d\u9700\u8981\u5355\u72ec\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ea\u9700\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u3002 \u9996\u5148\uff0cWebMan\u6280\u672f\u5e26\u6765\u4e86\u667a\u80fd\u5bb6\u5c45\u8bbe\u5907\u7684\u96c6\u4e2d\u7ba1\u7406\u3002\u5728\u4f20\u7edf\u7684\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u9700\u8981\u5b89\u88c5\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bcf\u4e2a\u8bbe\u5907\u5bf9\u5e94\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u7ed9\u7528\u6237\u5e26\u6765\u4e86\u4e0d\u4fbf\u3002\u800c\u4f7f\u7528WebMan\u6280\u672f\uff0c\u7528\u6237\u53ea\u9700\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u8bbe\u5907\u7684IP\u5730\u5740\uff0c\u5c31\u80fd\u591f\u8bbf\u95ee\u548c\u7ba1\u7406\u6240\u6709\u7684\u667a\u80fd\u8bbe\u5907\u3002\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\uff0c\u800c\u4e14\u53ef\u4ee5\u51cf\u5c11\u624b\u673a\u5b58\u50a8\u7a7a\u95f4\u7684\u5360\u7528\u3002 \u5176\u6b21\uff0cWebMan\u6280\u672f\u63d0\u4f9b\u4e86\u8fdc\u7a0b\u63a7\u5236\u7684\u529f\u80fd\u3002\u4f7f\u7528\u4f20\u7edf\u7684\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\uff0c\u7528\u6237\u53ea\u80fd\u5728\u5bb6\u91cc\u624d\u80fd\u63a7\u5236\u8bbe\u5907\uff0c\u4e00\u65e6\u79bb\u5f00\u5bb6\u5c31\u65e0\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\u4f46\u662f\uff0c\u901a\u8fc7WebMan\u6280\u672f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u901a\u8fc7\u4e92\u8054\u7f51\u8bbf\u95ee\u8bbe\u5907\uff0c\u5e76\u8fdb\u884c\u64cd\u4f5c\u63a7\u5236\u3002\u6bd4\u5982\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4e0a\u73ed\u7684\u8def\u4e0a\u63d0\u524d\u6253\u5f00\u5bb6\u91cc\u7684\u7a7a\u8c03\uff0c\u56de\u5230\u5bb6\u540e\u5c31\u80fd\u611f\u53d7\u5230\u51c9\u723d\u7684\u73af\u5883\u3002\u8fd9\u79cd\u8fdc\u7a0b\u63a7\u5236\u7684\u7075\u6d3b\u6027\u4e3a\u7528\u6237\u5e26\u6765\u4e86\u66f4\u52a0\u4fbf\u6377\u7684\u4f53\u9a8c\u3002 \u53e6\u5916\uff0cWebMan\u6280\u672f\u8fd8\u80fd\u591f\u5b9e\u73b0\u8bbe\u5907\u7684\u72b6\u6001\u76d1\u6d4b\u548c\u53c2\u6570\u8bbe\u7f6e\u3002\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u8bbe\u5907\u7684\u7ba1\u7406\u754c\u9762\uff0c\u7528\u6237\u53ef\u4ee5\u968f\u65f6\u67e5\u770b\u8bbe\u5907\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u6bd4\u5982\u6e29\u5ea6\u3001\u6e7f\u5ea6\u7b49\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u8bbe\u7f6e\u8bbe\u5907\u7684\u53c2\u6570\uff0c\u5982\u5b9a\u65f6\u5f00\u5173\u673a\u3001\u6a21\u5f0f\u9009\u62e9\u7b49\u3002\u8fd9\u79cd\u4e2a\u6027\u5316\u7684\u8bbe\u5907\u7ba1\u7406\u529f\u80fd\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7528\u6237\u7684\u9700\u6c42\u3002 \u4e0b\u9762\uff0c\u6211\u6765\u4ecb\u7ecd\u4e00\u4e2a\u4f7f\u7528WebMan\u6280\u672f\u7684\u667a\u80fd\u5bb6\u5c45\u5b9e\u4f8b\uff0c\u5e76\u6f14\u793a\u4e00\u4e0b\u4ee3\u7801\u793a\u4f8b\u3002 \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u667a\u80fd\u5bb6\u5c45\u7cfb\u7edf\uff0c\u5305\u62ec\u4e00\u4e2a\u6e29\u5ea6\u4f20\u611f\u5668\u548c\u4e00\u4e2a\u706f\u5149\u63a7\u5236\u5668\u3002\u6e29\u5ea6\u4f20\u611f\u5668\u8d1f\u8d23\u76d1\u6d4b\u623f\u95f4\u7684\u6e29\u5ea6\uff0c\u800c\u706f\u5149\u63a7\u5236\u5668\u53ef\u4ee5\u63a7\u5236\u623f\u95f4\u7684\u706f\u5149\u5f00\u5173\u3002 \u9996\u5148\uff0c\u6211\u4eec\u8981\u521b\u5efa\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u7528\u4e8e\u63d0\u4f9b\u8bbe\u5907\u7684\u7ba1\u7406\u529f\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684Flask\u6846\u67b6\u6765\u642d\u5efa\u7b80\u5355\u7684\u670d\u52a1\u5668\u3002 from flask import Flask, render_template app = Flask(__name__) @app.route(&#8216;\/&#8217;) def index(): return render_template(&#8216;index.html&#8217;) @app.route(&#8216;\/api\/temperature&#8217;) def get_temperature(): temperature = 25.5 # \u4ece\u6e29\u5ea6\u4f20\u611f\u5668\u83b7\u53d6\u5b9e\u9645\u6e29\u5ea6 return str(temperature) @app.route(&#8216;\/api\/light&#8217;, methods=[&#8216;GET&#8217;, &#8216;POST&#8217;]) def control_light(): if request.method == &#8216;POST&#8217;: # \u4ece\u8bf7\u6c42\u4e2d\u83b7\u53d6\u706f\u5149\u72b6\u6001 status = request.form[&#8216;status&#8217;] # \u5c06\u706f\u5149\u72b6\u6001\u4f20\u8f93\u7ed9\u706f\u5149\u63a7\u5236\u5668\uff0c\u5b9e\u73b0\u706f\u5149\u5f00\u5173\u63a7\u5236 else: # \u4ece\u706f\u5149\u63a7\u5236\u5668\u83b7\u53d6\u5f53\u524d\u706f\u5149\u72b6\u6001 status = &#8216;on&#8217; 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-24347","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24347","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=24347"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24347\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}