我有一个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应用程序,每个应用程序中都有多个路由
我不知道
但如果您试图绑定几个flask服务器,只需为每个进程选择另一个端口即可。 当你要求他们时,当然要注意港口
如果您正在努力实际制作多路由服务器,heres a good example.
相关问题 更多 >
编程相关推荐