使用烧瓶在客户端和服务器之间传递信息

pass information between client and server using flask

我在 http://127.0.0.1:5000/ and server_app.py running on http://127.0.0.1:5001/ client_app.py 运行 他们每个人在程序中都有一个 json 对象。 server_app.py 如何将字符串发送到 client_app 以更新其 json 对象? 谁能给我举个例子吗? 谢谢

您可以使用 requests 向其他应用程序发送 POST 请求。

您应用中的某处:

import requests

def update_other(self, data):
    r = requests.post("http://127.0.0.1:5000", data=data)
    ...

http://docs.python-requests.org/en/latest/

  1. 从服务器到客户端你可以使用Context Processors或者Martin Samson建议的方法

  2. 从客户端到服务器你可以使用jquery or flask's url_for