Wednesday, 15 September 2010

python flask before_request exclude /static directory -



python flask before_request exclude /static directory -

thanks reply below, have before_request function redirects user /login if have not yet logged in:

flask before request - add together exception specific route

here re-create of before_request:

@app.before_request def before_request(): if 'logged_in' not in session , request.endpoint != 'login': homecoming redirect(url_for('login'))

files in static directory not beingness served unless user logged in.

on /login page sourcing css file /static directory can not loaded because of before_request.

i have deployed application using apache mod_wsgi , in apache configuration file have included /static directory site's documentroot.

how can add together exception serve application's /static files without user logging in, still utilize before_request routes defined flask application?

you'll need add together alias or aliasmatch directive apache config file (or .htaccess file, should not have access .conf files) ensure apache serves static files, rather flask. create sure have provided directory allow apache web server access static path. (also, don't forget restart apache if editing .conf files changes picked up).

as temporary stop-gap measure (or create easy work in development) check create sure string /static/ not in request.path:

if 'logged_in' not in session \ , request.endpoint != 'login' \ , '/static/' not in request.path:

python flask mod-wsgi

No comments:

Post a Comment