general03 / flask-autoindex Goto Github PK
View Code? Open in Web Editor NEWGenerates index page like mod_autoindex
Home Page: https://flask-autoindex.readthedocs.io
License: MIT License
Generates index page like mod_autoindex
Home Page: https://flask-autoindex.readthedocs.io
License: MIT License
I use create_app
to create app. So I need create AutoIndex instance before app. But I can't find the init_app()
method in Flask-AutoIndex like other extensions.
The test suite of Flask-AutoIndex fails similarly to the one of Flask-Silk:
test_contain (tests.RootDirectoryTestCase) ... ok
test_get_child_dir (tests.RootDirectoryTestCase) ... ok
test_get_child_file (tests.RootDirectoryTestCase) ... ok
test_init (tests.RootDirectoryTestCase) ... ok
test_root_dir (tests.RootDirectoryTestCase) ... ok
test_same_object (tests.RootDirectoryTestCase) ... ok
test_contain (tests.DirectoryTestCase) ... ok
test_dir (tests.DirectoryTestCase) ... ok
test_get_child_file (tests.DirectoryTestCase) ... ok
test_init (tests.DirectoryTestCase) ... ok
test_same_object (tests.DirectoryTestCase) ... ok
test_file (tests.FileTestCase) ... ok
test_init (tests.FileTestCase) ... ok
test_properties (tests.FileTestCase) ... ok
test_same_object (tests.FileTestCase) ... ok
test_autoindex (tests.ApplicationTestCase) ... ERROR
test_builtin_icon_rule (tests.ApplicationTestCase) ... ERROR
test_css (tests.ApplicationTestCase) ... ERROR
test_custom_icon_rule (tests.ApplicationTestCase) ... ERROR
test_icon (tests.ApplicationTestCase) ... ERROR
test_own_page (tests.ApplicationTestCase) ... ERROR
test_own_static_file (tests.ApplicationTestCase) ... ERROR
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Traceback (most recent call last):
File "/home/sebastian/development/flask-autoindex/tests/init.py", line 134, in setUp
self.app2 = Flask(name + '2')
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 277, in init
template_folder=template_folder)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 572, in init
self.root_path = get_root_path(self.import_name)
File "/usr/lib/python2.7/dist-packages/flask/helpers.py", line 482, in get_root_path
import(import_name)
ImportError: No module named tests2
Ran 22 tests in 0.014s
FAILED (errors=7)
Fails: from flask.ext.autoindex import AutoIndex
Error: ModuleNotFoundError: No module named 'flask.ext'
site-packages (19.2.1)
pip freeze
Click==7.0
Flask==1.1.1
Flask-AutoIndex==0.6.4
Flask-Silk==0.2
future==0.17.1
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
is it possible to change the default sorting when invoking render_autoindex
without using a custom template?
If i pass the parameters in the url they are lost after the first click:
http://host/logs?sort_by=modified&order=desc
I've tried with:
idx.render_autoindex(path, endpoint = 'logs_view', sort_by='modified', order=-1)
Hello sublee,
I pushed merge request few weeks ago #43 but there are no update on pypi (and I need it)
I know you don't maintain this repo but if you want I can manage the repo to continue the project
Thanks
Hello!
could you please clarify, is it possible to download images from autoindex as attachment
not via opened in browser.
thank you
Now that flask finally supports Python 3.3, I tried to build and test flask-autoindex with Python 3.3. flask-silk seems to work without problems, but the test suite of flask-autoindex fails with:
% python3 setup.py test
running test
running egg_info
writing Flask_AutoIndex.egg-info/PKG-INFO
writing requirements to Flask_AutoIndex.egg-info/requires.txt
writing dependency_links to Flask_AutoIndex.egg-info/dependency_links.txt
writing top-level names to Flask_AutoIndex.egg-info/top_level.txt
reading manifest file 'Flask_AutoIndex.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Flask_AutoIndex.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 54, in <module>
'Topic :: Software Development :: Libraries :: Python Modules'
File "/usr/lib/python3.3/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.3/distutils/dist.py", line 929, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.3/distutils/dist.py", line 948, in run_command
cmd_obj.run()
File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 138, in run
self.with_project_on_sys_path(self.run_tests)
File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 118, in with_project_on_sys_path
func()
File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 164, in run_tests
testLoader = cks
File "/usr/lib/python3.3/unittest/main.py", line 124, in __init__
self.parseArgs(argv)
File "/usr/lib/python3.3/unittest/main.py", line 168, in parseArgs
self.createTests()
File "/usr/lib/python3.3/unittest/main.py", line 175, in createTests
self.module)
File "/usr/lib/python3.3/unittest/loader.py", line 137, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python3.3/unittest/loader.py", line 137, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python3.3/unittest/loader.py", line 122, in loadTestsFromName
test = obj()
File "setup.py", line 25, in run_tests
from tests import suite
File "/home/sebastian/development/flask-autoindex/tests/__init__.py", line 5, in <module>
from flask.ext.autoindex import *
File "/usr/lib/python3/dist-packages/flask/exthook.py", line 81, in load_module
reraise(exc_type, exc_value, tb.tb_next)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 32, in reraise
raise value.with_traceback(tb)
File "/home/sebastian/development/flask-autoindex/flask_autoindex/__init__.py", line 16, in <module>
from .entry import *
File "/home/sebastian/development/flask-autoindex/flask_autoindex/entry.py", line 3, in <module>
from urlparse import urljoin
ImportError: No module named 'urlparse'
It would be great if this could be fixed and flask-autoindex be ported to Python 3.3.
Hi,
we are very happily using flask-autoindex to enable browsing through our server's file system.
However, we get a UnicodeEncodeError
if there is a file/folder with special characters (in our case Umlaute) in the dirtree.
It seems as if macros.html line 10: <a href="{{ url_for(endpoint, path=ent.path) }}">
is responsible for it.
Is there any way to solve this issue? (Python 3.8 on Ubuntu 20.04)
Tests fail with this pattern:
$ PYTHONPATH=$PWD/build/lib/flaskext:$PYTHONPATH python tests/__init__.py
...............EEEEEEE
======================================================================
ERROR: test_autoindex (__main__.ApplicationTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/__init__.py", line 139, in setUp
def autoindex(path='.'):
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1013, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/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: autoindex
But this is the only failure pattern.
hi,
as i saw in the code 'render_autoindex' calls 'render_template' and passes its own context-dict
, so if a user want to make his own template and pass his own parameters two template it crashes.
the paramter 'form' throws an exception because it cannot be added to the 'render_autoindex'
Hello, whether to provide the function to hide files or folders.
Hello!
could you please help is it possible to use this library when multiple large file download exist.
Or just replace it by asyncio.
thank you
I've got a Flask app that I'm using Flash-AutoIndex in, and would like to be able to navigate it using the keyboard, so using arrow keys to navigate the links, and the enter key to enter a folder, and Escape key to exit a folder, and return to the parent.
I have started to implement this in javascript, but wonder if there's an easy way to implement this with pure html, but if not, with simple javascript?
I get the following error:
Running on http://127.0.0.1:5000/
Restarting with reloader
127.0.0.1 - - [22/Aug/2013 20:55:36] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "G:\workspace\flask-test\lib\site-packages\flask\app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "G:\workspace\flask-test\lib\site-packages\flask_autoindex\__init__.py", line 80, in autoindex
return self.render_autoindex(path)
File "G:\workspace\flask-test\lib\site-packages\flask_autoindex\__init__.py", line 101, in render_autoindex
curdir = Directory(path, rootdir)
File "G:\workspace\flask-test\lib\site-packages\flask_autoindex\entry.py", line 37, in __call__
ent = cls.__new__(cls, *args, **kwargs)
File "G:\workspace\flask-test\lib\site-packages\flask_autoindex\entry.py", line 216, in __new__
if os.path.samefile(os.path.join(rootpath, path), rootpath):
AttributeError: 'module' object has no attribute 'samefile'
Source code (taken from the documentation):
import os.path
from flask import Flask
from flask.ext.autoindex import AutoIndex
app = Flask(__name__)
AutoIndex(app, browse_root=os.path.curdir)
if __name__ == '__main__':
app.run(debug=True)
Output from pip freeze (I have only pip installed flask and flask-autoindex):
Flask==0.10.1
Flask-AutoIndex==0.5
Flask-Silk==0.2
Jinja2==2.7.1
MarkupSafe==0.18
Werkzeug==0.9.3
itsdangerous==0.23
I'm running in a virtualenv (flask-test) on Windows, Python 2.7.3
Any ideas or pointers?
Thanks!
by accessing http://localhost:80/.\..
note: tested on Windows with a quick hack to workaround #17 (as suggested on #14 ), but I think it would also work on Linux etc.
This should be trivial to correct, like my previous issue for flask-silk, that is, to add LICENSE and possibly the tests subdirectory to MANIFEST.in.
The fedora review request is at https://bugzilla.redhat.com/show_bug.cgi?id=839097
Not sure if this is how the tests should be done, but I get this:
$ python __init__.py .................F.... ====================================================================== FAIL: test_css (__main__.ApplicationTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "__init__.py", line 157, in test_css assert 200 == rv.status_code AssertionError ---------------------------------------------------------------------- Ran 22 tests in 0.206s FAILED (failures=1)
so I suppose there is a missing static/autoindex.css
file.
Latest version is 0.6 but the module sets version to 0.5.
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?
Hi
I was wondering if it is possible to use this extension to browser a configurable file-system path at a given sub-route in the application?
...
Autoindex(app, <any os path root>
@app.route('/browsefilesystem/<path:path>')
@app.route('/browsefilesystem')
def browse_file_system(path):
<instruct autoroute to do it's thing>
Thanks!
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!
After pushing Flask 2.2 to the Debian archive flask-autotest own test suite is failing within the check test_own_page()
.
While ruuning the package build the following error is happen.
...
test_parent_of_root (tests.ApplicationTestCase.test_parent_of_root) ... ok
test_sort (tests.SortTestCase.test_sort) ... ok
======================================================================
FAIL: test_own_page (tests.ApplicationTestCase.test_own_page)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/build/flask-autoindex-0.6.6/tests/__init__.py", line 186, in test_own_page
@self.app.route('/test')
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/flask/scaffold.py", line 49, in wrapper_func
self._check_setup_finished(f_name)
File "/usr/lib/python3/dist-packages/flask/app.py", line 722, in _check_setup_finished
raise AssertionError(
AssertionError: The setup method 'route' can no longer be called on the application. It has already handled its first request, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the application are done before running it.
----------------------------------------------------------------------
Ran 24 tests in 0.170s
FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=24 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=24 errors=0 failures=1>
E: pybuild pybuild:386: test: plugin distutils failed with: exit code=1: python3.11 setup.py test
My knowledge to fix this problem is to poor, could you please have a look at this?
Hi, it seems that the license of flask-autoindex has changed from a BSD 3 clause to an MIT license.
However, there's no COPYING or COPYRIGHT file that specifies which MIT license (I assume the MIT Expat license since that is commonly used). Also, the documentation in docs/index.rst still declares that the project is released under the BSD license. Please clarify.
As a side-note, it seems that you've released version 0.6.5 on pypi, but haven't tagged the release yet in your git repository.
Thanks for your work.
Importing "cached_property" from werkzeug does not work anymore (https://github.com/general03/flask-autoindex/blob/master/flask_autoindex/__init__.py#L10), it should be imported from werkzeug.utils (https://github.com/pallets/werkzeug/blob/master/src/werkzeug/utils.py#L53).
There are probably more imports that need to be fixed, or just pin version of Werkzeug to 0.16.0.
Hello,
is it possible to set dark theme for the web page?
Thanks.
Hi,
I need to protect the access to my flask server with flask-login.
This is done by adding @login_required to the path I need to protect.
Example:
@app.route("/my/path")
@login_required
def test():
return 'hello'
With flask-autoindex the paths are dynamic, how can I force the user to login for every path ?
File "/home/chrsjo/.virtualenvs/arkenutils/lib/python2.7/site-package/flask_autoindex/entry.py", line 71, in new
raise IOError('{0} does not exists.'.format(abspath))
Expected/wanted behavior: ignore the link
Hi,
autoindex works when it is enabled by default on all routes (add_url_rules=True).
If I try autoindex on a specific route, it fails with werkzeug.routing.BuildError.
What I am doing wrong?
Code:
from flask import Flask
from flask.ext.autoindex import AutoIndex
app = Flask(name)
idx = AutoIndex(app,'/', add_url_rules=False)
@app.route('/')
def app_root():
return 'Hi!'
@app.route('/index')
def index():
return idx.render_autoindex('.')
if name == 'main':
app.run(host='0.0.0.0', debug=True)
I'm use Linux and python 3.4
The page's last modified fields look like this:
2016-04-08 18:55:59.502160
If it is not a feature, I think this will fix it:
flask_autoindex/entry.py:112
return datetime.fromtimestamp(os.path.getmtime(self.abspath)).replace(microsecond=0)
Sorry for my bad English
The error message thrown by Flask:
ExtDeprecationWarning: Importing flask.ext.silk is deprecated, use flask_silk instead.
Additionally, the docs suggest that one consume Flask-AutoIndex with the flask.ext.autoindex
import hook as opposed to the direct import name flask_autoindex
.
From the Flask docs:
Extension Import Transition
In early versions of Flask we recommended using namespace packages for Flask extensions, of the form
flaskext.foo
. This turned out to be problematic in practice because it meant that multipleflaskext
packages coexist. Consequently we have recommended to name extensionsflask_foo
overflaskext.foo
for a long time.Flask 0.8 introduced a redirect import system as a compatibility aid for app developers: Importing
flask.ext.foo
would tryflask_foo
andflaskext.foo
in that order.As of Flask 0.11, most Flask extensions have transitioned to the new naming schema. The
flask.ext.foo
compatibility alias is still in Flask 0.11 but is now deprecated โ you should useflask_foo
.
Just wondering if there's any plan to do a release soon, the version that installs with pip seems to be out of date
Because os.path.samefile is only available on unixes in python 2.x.
Hi, I currently have a login blueprint at '/' route which redirects the user to '/files'.
'/files' should show an index of the ppath directory.
However, it is not redirecting. Here is the main app:
app = Flask(__name__)
app.config['UPLOAD_PATH'] = ppath
app.register_blueprint(login)
AutoIndex(app, browse_root=ppath)
@app.route('/files', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
uploaded_files = request.files.getlist("file[]")
for uploaded_file in uploaded_files:
filename = secure_filename(uploaded_file.filename)
if filename != '':
uploaded_file.save(os.path.join(
app.config['UPLOAD_PATH'], filename))
return redirect(url_for('autoindex))
This is the login function at '/'
login = Blueprint('login_bp', __name__)
@login.route('/', methods=['GET','POST'])
def login_interface():
password = request.form.get('password')
print(password)
if password == '1234':
return redirect('/files')
return render_template('__autoindex__/login.html')
I am trying to get this up ind Docker.Pretty simple Dockerfile
FROM python:3.7.4
WORKDIR /app/
COPY . /app/
RUN pip install -r "requirements.txt"
EXPOSE 5000
ENTRYPOINT ["python", "app.py"]
And running as
docker run --name autoindex -p 5000:5000 -ti javadocs -v /folderview:/app
I have ppath="/app" in app.py . Any idea on what I might be missing ?
The imp module has been removed in Python 3.12, thus flask_autoindex 0.6.6 run into problem:
app\app.py:11: in <module>
import flask_autoindex
.venv\Lib\site-packages\flask_autoindex\__init__.py:12: in <module>
from . import icons
.venv\Lib\site-packages\flask_autoindex\icons.py:4: in <module>
from .entry import File, Default
.venv\Lib\site-packages\flask_autoindex\entry.py:2: in <module>
from future import standard_library
.venv\Lib\site-packages\future\standard_library\__init__.py:65: in <module>
import imp
E ModuleNotFoundError: No module named 'imp'
https://discuss.python.org/t/how-do-i-migrate-from-imp/27885
The sort order comes from the order
parameter in the request:
order = {'asc': 1, 'desc': -1}[request.args.get('order', 'asc')]
But you'll see that there's no validation of the parameter, so that passing ?order=bug
results in a KeyError
exception and a "500 Internal Server Error" response.
A more robust (and shorter!) alternative would be something like this:
order = -1 if request.args.get('order') == 'desc' else 1
from flask import Blueprint
from flask_autoindex import AutoIndexBlueprint
.
.
.
bp_ai = Blueprint('foo', __name__, static_folder='./static', template_folder='templates')
AutoIndexBlueprint(bp_ai, browse_root=f'{my_dir}',template_context=dict(x='y'))
.
.
.
app.register_blueprint(bp_ai, url_prefix='/foo/files')
This is how i am using AutoIndex. It Works.
But clicking on files directly open in browser. How do i enable force download on click?
In doc, i found no information about "as_attachment" parameter. What should i modify in those two lines to enable force download?
Please Help !
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_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)
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
Dear developers,
first of all, thank you very much for this useful library!
We used the version 0.6.4 without issues, but now, using the version 0.6.6, we are experiencing a problem on the method render_autoindex('.') (that was working on the old version)
Is something changed in the syntax? Could you suggest something in particular in the documentation?
Thank you very much for all your support and all your work
Hi -
I would like to set MIME for e.g. yaml documents to text/plain so that yaml files can be directly viewed in the web browser rather than downloaded.
I tried e.g.
idx.add_icon_rule('my_yaml_icon.png', ext='yaml', mimetype='text/plain')
but the response header returned by flask still defaults to application/octet-stream. Can you please share example how to properly set mime based on file extension?
Thank you,
TIR
C:\taratmp\lib\site-packages\flask_autoindex_init_.py:18: ExtDeprecationWarning: Importing flask.ext.silk is deprecat
ed, use flask_silk instead.
Hello,
I installed Python 2.7 and 3.5, Flask, Virtual Venv and Flask-Autoindex via terminal. I restarted XAMPP. I updated the Apache Index and it wasn't well displayed.
XAMPP/htdocs/
)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.