Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index on a path other than root #16

Closed
blackfist opened this issue Sep 23, 2013 · 5 comments
Closed

Index on a path other than root #16

blackfist opened this issue Sep 23, 2013 · 5 comments

Comments

@blackfist
Copy link

I'm trying to find documentation on how to configure flask-autoindex to serve up a directory on a route other than /.

AutoIndex(app, browse_root='some_path')

Works and shows me the content when I visit http://localhost:5000/. I tried to do this

@app.route('/reports')
def report_path():
AutoIndex(app, browse_root='some_path')

And I get an error. What is the proper way to do what I'm trying to do?

@stephenbez
Copy link

I think this is the way to do it:

idx = AutoIndex(app, '/home/blackfist/reports', add_url_rules=False)

@app.route('/reports')
@app.route('/reports/<path:path>')
def autoindex(path='.'):
    return idx.render_autoindex(path)

I figured this out by reading the code for the AutoIndex constructor

@mrculler
Copy link

@stephenbez I'm seeing your solution get a bit closer to a working solution, but it still fails, I'm guessing because of flask-autoindex code changes since your comment here. Doing what you said makes a separately-routed autoindex work for an empty directory, but once there is a file or a subdirectory in there everything explodes.

BuildError: ('autoindex', {'path': './somefile'}, None)

I tried path.lstrip("./") and setting browse_root=False on the render_autoindex call but it nothing changed the output.

@astanway
Copy link

+1 for this feature - I also need to serve an auto index page on somewhere other than root.

@LarryKlugerDS
Copy link

The following is working for me:

files_index = AutoIndex(app, os.path.curdir + '/app/files', add_url_rules=False)
# Custom indexing
@app.route('/files')
@app.route('/files/<path:path>')
def autoindex(path='.'):
    return files_index.render_autoindex(path)

@general03
Copy link
Owner

You're right @LarryKlugerDS it's the solution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants