运行多个多路由应用程序

2024-10-16 20:49:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个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():

DispatcherMiddleware的帮助下,我试图用不同的参数多次实现它,但我遇到了麻烦。 以下是实际实现:

# 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路由,但这些按钮不起作用

一般的问题是,如何运行多个flash应用程序,每个应用程序中都有多个路由


Tags: importidapp应用程序路由indexapplicationuse