mitsuhiko/flask — Issue #357: flask_autoindex fails with flask 0.8.0 but works with 0.7.0
Author: davidthewatson
Created: 2011-12-06 03:33:16+00:00
State: open

I was having trouble with flask_autoindex which I documented here:

https://github.com/sublee/flask-autoindex/issues/1

This was installed with:

virtualenv --no-site-packages env
source env/bin/activate
pip install flask_autoindex

Here's the traceback

Traceback (most recent call last):
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1518, in call
return self.wsgi_app(environ, start_response)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app
response = self.full_dispatch_request()
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1262, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 1248, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/davidthewatson/github/flongo/flaskengine/views.py", line 31, in archive
idx = AutoIndex(app, browse_root=curdir)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flaskext/autoindex/init.py", line 203, in init
**silk_options)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flaskext/autoindex/init.py", line 72, in init
self.silk = Silk(self.base, **silk_options)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flaskext/silk/init.py", line 40, in init
self.silkicon = self.base.route(rule)(self.silkicon)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 923, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/Users/davidthewatson/github/flongo/env/lib/python2.7/site-packages/flask/app.py", line 56, in wrapper_func
raise AssertionError('A setup function was called after the '
AssertionError: A setup function was called after the first request was handled. This usually indicates a bug in the application where a module was not imported and decorators or other functionality was called too late.
To fix this make sure to import all your view modules, database models and everything related at a central place before the application starts serving requests.

The relevant code is:

from flaskext.autoindex import AutoIndex

@app.route('/archive/', methods=['GET'])
def archive(path='./archive'):
idx = AutoIndex(app, browse_root=curdir)
return idx.render_autoindex(path)

However, this works fine when I pip uninstall flask and pip install -I flask==0.7.0. I'm not sure where the bug is, but I thought I'd mention it in case I did something wrong or it can be resolved such that the default pip installed version will work in virtualenv.

Thanks.