{"id":8169,"library":"flask-autoindex","title":"Flask-AutoIndex","description":"Flask-AutoIndex is a Flask extension that automatically generates index pages for Flask applications, mimicking Apache's mod_autoindex. It provides a default visual style for directory listings but also allows for extensive customization of templates and icons. The current stable version is 0.6.6, released in March 2020. While functional, the project appears to be in maintenance mode, with limited recent activity on its GitHub repository.","status":"maintenance","version":"0.6.6","language":"en","source_language":"en","source_url":"https://github.com/general03/flask-autoindex","tags":["Flask","autoindex","directory listing","web server","files"],"install":[{"cmd":"pip install Flask-AutoIndex","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core web framework integration.","package":"Flask","optional":false},{"reason":"Used internally by Flask-AutoIndex to serve icons for the directory listings.","package":"Flask-Silk","optional":false}],"imports":[{"note":"The `flask.ext` namespace was deprecated and removed in newer Flask versions (Flask 0.11+). Direct import from the package name is required.","wrong":"from flask.ext.autoindex import AutoIndex","symbol":"AutoIndex","correct":"from flask_autoindex import AutoIndex"}],"quickstart":{"code":"import os\nfrom flask import Flask\nfrom flask_autoindex import AutoIndex\n\napp = Flask(__name__)\n\n# Create a dummy directory and file for demonstration\ndemo_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'my_files')\nos.makedirs(demo_dir, exist_ok=True)\nwith open(os.path.join(demo_dir, 'example.txt'), 'w') as f:\n    f.write('This is an example file managed by Flask-AutoIndex.')\n\n# Initialize AutoIndex to serve 'my_files' directory\n# We set add_url_rules=False to manually define the route, preventing conflicts.\nidx = AutoIndex(app, browse_root=demo_dir, add_url_rules=False)\n\n@app.route('/')\ndef home():\n    return \"<h1>Welcome!</h1><p>Visit <a href='/files'>/files</a> for the auto-indexed directory.</p>\"\n\n# Manually define routes for AutoIndex to serve content\n@app.route('/files')\n@app.route('/files/<path:path>')\ndef autoindex(path='.'):\n    # Call render_autoindex with the path to display the directory content\n    return idx.render_autoindex(path)\n\nif __name__ == '__main__':\n    app.run(debug=True)","lang":"python","description":"This quickstart initializes a Flask application and configures Flask-AutoIndex to serve files from a 'my_files' directory at the `/files` URL path. It explicitly sets `add_url_rules=False` to allow for manual routing, preventing potential conflicts with other Flask routes. Run the script and navigate to `http://127.0.0.1:5000/files` to see the auto-indexed content."},"warnings":[{"fix":"Ensure your project is running on Python 3.6+ for Flask-AutoIndex 0.6.4 and above. Use an older version if Python 2 compatibility is essential (not recommended).","message":"Versions of Flask-AutoIndex prior to 0.6.4 supported Python 2. Versions 0.6.4 and newer require Python 3.6 or higher. Attempting to use newer versions on Python 2 will result in syntax errors or import issues.","severity":"breaking","affected_versions":"<0.6.4 (Python 2), >=0.6.4 (Python 3.6+)"},{"fix":"When initializing `AutoIndex`, always set `add_url_rules=False` if you intend to define your own `@app.route` decorators for serving the indexed content. Then, manually add the desired routes as shown in the quickstart example.","message":"By default, if `add_url_rules` is not explicitly set to `False` during initialization, Flask-AutoIndex may automatically register routes like `/` or `/some_path` which could conflict with your application's custom routes, leading to `AssertionError: View function mapping is overwriting an existing endpoint function`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update your imports to `from flask_autoindex import AutoIndex`. Using `flask.ext` will result in `ModuleNotFoundError`.","message":"The `flask.ext` import pattern (e.g., `from flask.ext.autoindex import AutoIndex`) is an outdated Flask mechanism. In modern Flask (0.11+), extensions are imported directly from their package name.","severity":"gotcha","affected_versions":"Flask 0.11+ (when used with Flask-AutoIndex)"},{"fix":"Be aware that active development might be slow. Consider auditing the code or having a fallback if high-maintenance or cutting-edge features are required.","message":"The project shows limited recent development activity, with the last PyPI release in March 2020 and last GitHub commit in 2024 (but main functionality largely unchanged since 2020). While it remains functional, it may not receive updates for new Flask features or critical bug fixes promptly.","severity":"gotcha","affected_versions":"0.6.6 and potentially future versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from flask_autoindex import AutoIndex`.","cause":"Attempting to import Flask-AutoIndex using the old `flask.ext` namespace, which was removed in modern Flask versions (0.11+).","error":"ModuleNotFoundError: No module named 'flask.ext'"},{"fix":"When initializing `AutoIndex`, pass `add_url_rules=False` and then define your routes for `AutoIndex` manually using `@app.route` decorators and calling `idx.render_autoindex(path)` in the view function, as shown in the quickstart.","cause":"This error occurs when Flask-AutoIndex's automatic URL rule creation conflicts with a manually defined Flask route that uses the same endpoint name (often 'autoindex' by default) or URL path.","error":"AssertionError: View function mapping is overwriting an existing endpoint function: autoindex"},{"fix":"Initialize `AutoIndex` with `add_url_rules=False` and explicitly define your `AutoIndex` routes for a specific path (e.g., `/files`), allowing your root path (`/`) to be handled by a separate Flask view function.","cause":"By default, if `AutoIndex` is initialized without specifying `add_url_rules=False` and `browse_root` points to a high-level directory (like `os.path.curdir`), it can take over the root URL (`/`).","error":"Flask-AutoIndex is serving files from '/' (the root of my application) instead of my custom home page."}]}