Thanks to the answer below, I have a before_request function which redirects a user to /login if they have not yet logged in:
flask before request - add exception for specific route
Here is a copy of my before_request:
@app.before_request
def before_request():
if 'logged_in' not in session and request.endpoint != 'login':
return redirect(url_for('login'))
Files in my static directory are not being served however unless the user is logged in.
On my /login page I am sourcing a css file from the /static directory but it can not be loaded because of this before_request.
I have deployed this application using apache mod_wsgi and in my apache configuration file I have even included the /static directory as the site's DocumentRoot.
How can I add an exception to serve my application's /static files without the user logging in, but still use this before_request for the routes defined by my flask application?