Python 使用DispatcherMiddware的wsgi_应用程序的URL
我有两个应用程序工厂功能-一个创建“客户”应用程序,另一个创建“管理员”后端应用程序。这两个工厂函数本质上都做了所描述的事情——创建一个flask应用程序并注册一些扩展,然后添加一些蓝图(带有url_前缀)。我通过下面的Python 使用DispatcherMiddware的wsgi_应用程序的URL,python,flask,wsgi,Python,Flask,Wsgi,我有两个应用程序工厂功能-一个创建“客户”应用程序,另一个创建“管理员”后端应用程序。这两个工厂函数本质上都做了所描述的事情——创建一个flask应用程序并注册一些扩展,然后添加一些蓝图(带有url_前缀)。我通过下面的create\u combined\u app()将两个应用粘在一起。它是我在Flask脚本的管理器中注册的函数的返回值 def create_combined_app(config_name): customer_app = create_customer_app(co
create\u combined\u app()
将两个应用粘在一起。它是我在Flask脚本的管理器中注册的函数的返回值
def create_combined_app(config_name):
customer_app = create_customer_app(config_name)
admin_app = create_admin_app(config_name)
from werkzeug.wsgi import DispatcherMiddleware
customer_app.wsgi_app = DispatcherMiddleware(customer_app.wsgi_app, {
'/admin': admin_app
})
return customer_app
然后这就是我运行它的方式
def make_me_an_app():
return create_combined_app(config)
manager = Manager(make_me_an_app)
...
if __name__ == '__main__':
manager.run()
我想做一些测试,包括获取我的应用程序的所有GET路径,并确保它们加载。我遵循了中的示例,但我只看到了客户应用程序的URL,而没有看到管理员后端的URL
@main.route("/site-map")
def site_map():
from flask import current_app, jsonify
links = []
app = current_app
for rule in app.url_map.iter_rules():
if "GET" in rule.methods and has_no_empty_params(rule):
url = url_for(rule.endpoint, **(rule.defaults or {}))
links.append((url, rule.endpoint))
return jsonify(links)
当我尝试从浏览器访问管理员后端时,它工作得很好,只是当我调用/sitemap时,我看不到管理员的URL
谢谢!:) 我认为Dispatchermidware可以创建单独的应用程序。这意味着您创建了客户应用程序和管理员应用程序。这两个独立存在。他们彼此不认识,因此当前的应用程序只是显示客户应用程序
这是烧瓶里的描述