Created
October 3, 2014 16:30
-
-
Save hirobert/b954b29ff9f6396e7218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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