python flask before_request exclude /static directory
感谢下面的回答,我有一个
请求前先进行烧瓶-为特定路线添加例外
这是我的before_request的副本:
1 2 3 4 | @app.before_request def before_request(): if 'logged_in' not in session and request.endpoint != 'login': return redirect(url_for('login')) |
但是,除非用户登录,否则不会提供我的静态目录中的文件。
在我的
我已经使用apache mod_wsgi部署了该应用程序,并且在我的apache配置文件中,我什至包括了
如何在没有用户登录的情况下添加例外来为我的应用程序的
您需要向Apache配置文件(或.htaccess文件,如果您无权访问
作为临时的权宜之计(或使其易于在开发中使用),您还可以检查以确保字符串
1 2 3 | if 'logged_in' not in session \\ and request.endpoint != 'login' \\ and '/static/' not in request.path: |
我认为有一个比检查
1 2 | if 'logged_in' not in session and request.endpoint not in ('login', 'static'): return redirect(url_for('login')) |
我确实同意Apache的方法,但是为了快速解决,我在before_request()函数开始时使用了以下逻辑:
1 2 | if flask.request.script_root =="/static": return |