flask多app应用(url进行处理和分发)
from flask import Flask from werkzeug.wsgi import DispatcherMiddleware from werkzeug.serving import run_simple app01 = Flask('app01') app02 = Flask('app02') @app01.route('/login') def login(): return 'app01.login' @app02.route('/index') def index(): return 'app02.index' dm = DispatcherMiddleware(app01,{ '/app02': app02, }) if __name__ == '__main__': run_simple('localhost', 5000,dm)
我们可以创建多个app,并同时运行,访问app01时可以直接使用/login,访问app02时需要使用/app02/index