python flask before_request exclude /static directory
You'll need to add an Alias
or AliasMatch
directive to your Apache config file (or .htaccess file, should you not have access to the .conf
files) to ensure that Apache serves your static files, rather than Flask. Make sure that you have provided a Directory
to allow the Apache web server to access your static path. (Also, don't forget to restart Apache if you are editing the .conf
files so your changes will be picked up).
As a temporary stop-gap measure (or to make it easy to work with in development) you could also check to make sure that the string /static/
is not in request.path
:
if 'logged_in' not in session \ and request.endpoint != 'login' \ and '/static/' not in request.path: