sublee/flask-autoindex — Issue #1: autoindex failing in virtualenv
Author: davidthewatson
Created: 2011-11-29 04:43:45+00:00
State: open

Hi, I've had the same code unchanged for a while now, but as of the latest rev in my virtualenv, it seems to have broken. 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_functions[rule.endpoint](**req.view_args)
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)

I'm not sure what is wrong, but I guessed that something may have changed in the now deprecated flaskext module. I'm not sure what the code should look like beyond the deprecation of flaskext but please let me know if my code is wrong. It's been working for months now unchanged.

Thanks,
David