Skip to content

Instantly share code, notes, and snippets.

@hirobert
Created October 3, 2014 16:30
Show Gist options
  • Save hirobert/b954b29ff9f6396e7218 to your computer and use it in GitHub Desktop.
Save hirobert/b954b29ff9f6396e7218 to your computer and use it in GitHub Desktop.
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