I want to insert an AutoIndex inside a HTML page with more content..Something like this
<html>
<body>
//HTML Content here like IMG, DIV, Table
// Autoindex here
</body>
</html>
I am using autoindex like this, but it covers whole page
import os.path
from flask import Flask
from flask_autoindex import AutoIndex
app = Flask(__name__)
return AutoIndex(app, browse_root='templates/computer1')
if __name__ == '__main__':
app.run()
I've managed this by doing the following:
Create your customized .html
template
# mytemplate.html
{% extends '__autoindex__/autoindex.html' %}
{% block meta %}
{{ super() }}
<link rel="stylesheet"
href="{{ url_for('static', filename='main.css') }}" />
<!-- Here you can specify your own .css -->
{% endblock %}
{% block header %}
<div style="width: 500px; margin: 30px auto;">
<h2>My Application</h2>
{% endblock %}
{% block footer %}
</div>
{% endblock %}
(This is the template shown in the docs, you can customize this)
And in python, in order to run AutoIndex on that template:
# faicustom.py
from flask import Flask
from flask_autoindex import AutoIndex
app = Flask(__name__)
spath = "/" # Update your own starting directory here, or leave "/" for parent directory
files_index = AutoIndex(app, browse_root=spath, add_url_rules=False)
@app.route('/files')
@app.route('/files/<path:path>')
def autoindex(path='.'):
return files_index.render_autoindex(path, template='mytemplate.html')
# Here is where you specify your template
# And if you want:
if __name__ == '__main__':
app.run()
Then start the flask app and should be able to run AutoIndex on your own custom site (in this case at /files
)
For more info on the render_autoindex
function, check the commented source code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With