general03 / flask-autoindex

Generates index page like mod_autoindex
https://flask-autoindex.readthedocs.io
MIT License
112 stars 35 forks source link

Autoindex for multiple (specific directories) #25

Open vsoch opened 9 years ago

vsoch commented 9 years ago

Hi,

I want to define a custom route for the root (@root("/")) and then auto index only a specific set of directories from there. However, when I define multiple autoindex, it tells me that I am overwriting existing end point functions. For example:

app = Flask(__name__)
timeseries_index = AutoIndex(app,"/var/www/timeseries",add_url_rules=False)
rna_index = AutoIndex(app,"/var/www/rna-seq",add_url_rules=False)
meta_index = AutoIndex(app,"/var/www/timeseries",add_url_rules=False)

# Custom indexing
@app.route('/timeseries')
@app.route('/timeseries/<path:path>')
def tindex(path='.'):
    return timeseries_index.render_autoindex(path)

# Custom indexing
@app.route('/rna-seq')
@app.route('/rna-seq/<path:path>')
def rindex(path='.'):
    return rna_index.render_autoindex(path)

# Custom indexing
@app.route('/metabolomics')
@app.route('/metabolomics/<path:path>')
def mindex(path='.'):
    return meta_index.render_autoindex(path)

# Main myconnectome analyses page
@app.route('/')
def show_analyses():
       ...etc

I get the same error when I move the *_index inside the route functions.

Error:

      Traceback (most recent call last):
  File "index.py", line 11, in <module>
    rna_index = AutoIndex(app,"/var/www/rna-seq",add_url_rules=False)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask_autoindex/__init__.py", line 204, in __init__
    **silk_options)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask_autoindex/__init__.py", line 73, in __init__
    self.silk = Silk(self.base, **silk_options)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask_silk/__init__.py", line 61, in __init__
    self.silkicon = self.base.route(rule)(self.silkicon)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask/app.py", line 1013, in decorator
    self.add_url_rule(rule, endpoint, f, **options)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/vagrant/miniconda/lib/python2.7/site-packages/flask/app.py", line 984, in  add_url_rule
    'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: silkicon

Is there a better way to do this? The above functionality works only given that I define the AutoIndex once (eg, for one subdirectory). However I need to do it for several. Thanks for your help!

general03 commented 4 years ago

This example is on python 2.7 not more supported

WolfgangFahl commented 3 years ago
AssertionError: View function mapping is overwriting an existing endpoint function: silkicon

in python 3.8

general03 commented 3 years ago

Hi @WolfgangFahl ,

Could you put more information : code, how to reproduce ...

Thanks

apodobytko commented 3 years ago

This is how you can reproduce:

bc@anton-mbp ~/H/p/v/autoindex_multiple [1]> tree
.
├── app.py
├── first
│   └── 1.txt
└── second
    └── 2.txt

2 directories, 3 files
bc@anton-mbp ~/H/p/v/autoindex_multiple> cat app.py
from flask import Flask
from flask_autoindex import AutoIndex

app = Flask(__name__)

first = AutoIndex(app, "first", add_url_rules=False)
second = AutoIndex(app, "second", add_url_rules=False)

@app.route("/first")
@app.route("/first/<path:path>")
def first_index(path="."):
    return first.render_autoindex(path, endpoint=".first_index")

@app.route("/second")
@app.route("/second/<path:path>")
def second_index(path="."):
    return second.render_autoindex(path, endpoint=".second_index")

if __name__ == "__main__":
    app.run(debug=True)
bc@anton-mbp ~/H/p/v/autoindex_multiple> python app.py
Traceback (most recent call last):
  File "app.py", line 7, in <module>
    second = AutoIndex(app, "second", add_url_rules=False)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask_autoindex/__init__.py", line 242, in __init__
    **silk_options)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask_autoindex/__init__.py", line 78, in __init__
    self.silk = Silk(self.base, **silk_options)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask_silk/__init__.py", line 61, in __init__
    self.silkicon = self.base.route(rule)(self.silkicon)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask/app.py", line 1315, in decorator
    self.add_url_rule(rule, endpoint, f, **options)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask/app.py", line 98, in wrapper_func
    return f(self, *args, **kwargs)
  File "/Users/bc/.pyenv/versions/env/lib/python3.6/site-packages/flask/app.py", line 1284, in add_url_rule
    "existing endpoint function: %s" % endpoint
AssertionError: View function mapping is overwriting an existing endpoint function: silkicon
WolfgangFahl commented 3 years ago

thx for stepping in

general03 commented 3 years ago

It's FlaskSilk issue because you can't have several app on the same path.

general03 commented 3 years ago

A rework is needed, detach this library

flynn1973 commented 1 year ago

got same error today while trying to use multiple indexes in specific directoriers...any chance to get this fixed?

Using cacerts from /opt/freeware/lib/python3.7/site-packages/certifi/cacert.pem
Traceback (most recent call last):
  File "/home/tremch/flask/authlib_keycloak_client_test/app.py", line 32, in <module>
    daba_index = AutoIndex(app, '/srv/www/nmonchart/nmon4daba', add_url_rules=False)
  File "/opt/freeware/lib/python3.7/site-packages/flask_autoindex/__init__.py", line 242, in __init__
    **silk_options)
  File "/opt/freeware/lib/python3.7/site-packages/flask_autoindex/__init__.py", line 78, in __init__
    self.silk = Silk(self.base, **silk_options)
  File "/opt/freeware/lib/python3.7/site-packages/flask_silk/__init__.py", line 61, in __init__
    self.silkicon = self.base.route(rule)(self.silkicon)
  File "/opt/freeware/lib/python3.7/site-packages/flask/scaffold.py", line 449, in decorator
    self.add_url_rule(rule, endpoint, f, **options)
  File "/opt/freeware/lib/python3.7/site-packages/flask/scaffold.py", line 50, in wrapper_func
    return f(self, *args, **kwargs)
  File "/opt/freeware/lib/python3.7/site-packages/flask/app.py", line 1362, in add_url_rule
    "View function mapping is overwriting an existing"
AssertionError: View function mapping is overwriting an existing endpoint function: silkicon