【发布时间】:2022-09-28 03:32:37
【问题描述】:
我想在 POST 请求发生时重新启动烧瓶应用程序。
我的想法是一个网站,它是一个 index.html 文件,服务器写入发布的数据。
一个粗略的路径是这样的:
- 向服务器发送数据 --> 2. 处理数据 --> 3. 向服务器写入数据 --> 4. 重启 Flask 实例/更新 html
我已经到了第 3 部分。第 4 部分对我不起作用,我尝试任何方法。有人能帮我吗?
我也使用了render_template,这可能是问题所在。
当前代码:
#Server-Side @app.route(\"/\", methods=[\"POST\"]) def rnder(): f = open(\"templates/index.html\", \"wt\") f.write(str(request.json)) f.close() f = open(\"restart.py\", \"rt\") f = f.read() try: exec(f) except BrokenPipeError: sys.stdout = None quit() @app.route(\"/\", methods=[\"GET\"]) def hello(): return render_template(\'index.html\')#Sending Data data = {\"Hello World\": \"This is a test\"} requests.post(url=\"http://abcdefghijklmnopqrstuvw.xyz\", json=data)