Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from flask import Flask, send_from_directory
import os
app = Flask(__name__)
app.debug = True
_file_directory = 'files/'
@app.route('/')
def directory():
output_html = '<html>{0}</html>'
href_tag = '<a href="/download/{0}">{0}</a><br>'
file_links = ''
for filename in os.listdir(_file_directory):
if os.path.isfile(_file_directory + filename):
file_links += href_tag.format(filename)
return output_html.format(file_links)
@app.route('/download/<path:filename>')
def send_file(filename):
return send_from_directory(_file_directory, filename)
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment