如何使Flask在两台不同的机器上与Flask通信? [英] How to make Flask communicate with Flask across two different machines?

查看:120
本文介绍了如何使Flask在两台不同的机器上与Flask通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一台机器上有一个Flask应用程序,而另一台机器上需要运行一些查询.第二台机器不渲染任何页面,它只会在第一个应用程序的幕后工作.如果我在第二台计算机上创建Flask应用程序来控制这些查询,该如何从第一台应用程序与其通信?使用API​​编写第二个Flask应用程序是否正确,还是有更简单的方法来做到这一点?

I have a Flask app on one machine, and a second machine where some queries are required to be run from. The second machine doesn't render any pages, it will just be doing things behind the scenes for the first app. If I create a Flask app on the second machine to control those queries, how do I communicate with it from the first app? Is making a second Flask app with an API correct, or is there a simpler way to do this?

推荐答案

您可以像其他任何HTTP服务器一样与之通信:通过发出HTTP请求. Python具有内置的 urllib ,或考虑使用易于使用的请求库.

You communicate with it like you would any other HTTP server: by making HTTP requests. Python has the built-in urllib, or you could consider the easy to use requests library.

如果第二台计算机的所有运行都在运行后台任务,则没有理由设置另一个Flask应用程序.您可以使用任务队列(例如 Celery )或RPC库(例如

If all the second machine is doing is running background tasks, there's no reason to set up another Flask app. You can use a task queue such as Celery instead, or an RPC library such as Pyro.

这篇关于如何使Flask在两台不同的机器上与Flask通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆