Flask app wrapped with DispatcherMiddleware no longer has test_client

£可爱£侵袭症+ 提交于 2019-12-05 06:34:21

To add WSGI middleware to a Flask app, wrap and replace the app's wsgi_app attribute. You're replacing the reference to the Flask app with a reference to some other WSGI app, which obviously won't have the same properties. By replacing wsgi_app, you retain the reference to the Flask app but change the WSGI callable that backs it.

app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
    '/backend': backend_app
})

I was looking to use the test_client on both of the bundled apps. Here is a modification to davidism's answer that allowed me to use test clients for both:

app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
    '/backend': backend_app.wsgi_app
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!