Flask 多app案例
Flask 使用多app 连接不同数据库
离线脚本app_stack = ["app1", "app2"] #会有多个app
from flask import Flask from werkzeug.middleware.dispatcher import DispatcherMiddleware from werkzeug.serving import run_simple app1 = Flask("app1") app1.config["DB"] = "123" app2 = Flask("app2") app2.config["MYSQL"] = "456" @app1.route('/web') def web(): print("web") @app1.route('/news') def news(): print("news") @app2.route('admin') def admin(): print("admin") @app2.route('article') def article(): print("article") """ /web /news /app2/admin /app2/article """ app = DispatcherMiddleware(app1, { '/app2': app2, }) if __name__ == "__main__": run_simple(hostname="127.0.0.1", port=5000, application=app)