一. 多 app 使用
1.1 下载模块
pip3 install werkzeug
1.2 执行原理
1.3 使用
from flask import Flask
from werkzeug.serving import run_simple
from werkzeug.middleware.dispatcher import DispatcherMiddleware
# 创建两个 app
app01 = Flask('app01')
app02 = Flask('app02')
@app01.route('/index')
def index():
return "app01"
@app02.route('/index2')
def index2():
return "app2"
# 注意这里的写法
# 访问 app01 下的视图 : http://localhost:5000/index
# 访问 app02 下的视图 : http://localhost:5000/sec/index2 这里需加 /sec
dm = DispatcherMiddleware(app01, {'/sec': app02, })
if __name__ == '__main__':
# 这路必须用 run_simple 启动项目
run_simple('localhost', 5000, dm)