Python 运行多个多路由应用程序
我有一个flask应用程序脚本,它有多个路由Python 运行多个多路由应用程序,python,flask,gunicorn,werkzeug,Python,Flask,Gunicorn,Werkzeug,我有一个flask应用程序脚本,它有多个路由 #app.py def create_app(Tractor_id=0): @app.route("/") def index(): return render_template('index.html') @app.route("/id") def start(): return Tractor_id @app.route("/stop") def stop():
#app.py
def create_app(Tractor_id=0):
@app.route("/")
def index():
return render_template('index.html')
@app.route("/id")
def start():
return Tractor_id
@app.route("/stop")
def stop():
我试图在dispatchermidware
的帮助下使用不同的参数多次实现它,但我遇到了问题。
以下是实际实现:
# multiapp.py
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
import start
T1 = start.create_app(Tractor_id='101')
T2 = start.create_app(Tractor_id='102')
# merge
application = DispatcherMiddleware(
None, {
'/{}'.format('T101'): T1,
'/{}'.format('T102'): T2
}
)
if __name__ == '__main__':
run_simple(
hostname='localhost',
port=5000,
application=application,
use_reloader=True,
use_debugger=True,
use_evalex=True)
在index.html中,有一些按钮可以将用户重定向到/id和/stop路由,但这些按钮不起作用
一般的问题是,如何运行多个Flask应用程序,每个应用程序中都有多个路由?我不知道
DispatcherMiddleware
但如果您试图绑定几个flask服务器,只需为每个进程选择另一个端口即可。
当你要求他们时,当然要注意港口
如果您正在努力实际制作多路由服务器