Skip to content

Instantly share code, notes, and snippets.

@ibigbug
Created June 24, 2015 06:07
Show Gist options
  • Save ibigbug/c6f00f31160ac8313ccf to your computer and use it in GitHub Desktop.
Save ibigbug/c6f00f31160ac8313ccf to your computer and use it in GitHub Desktop.
Very simple static folder server using Flask
from flask import Flask
from flask import request
from flask import jsonify
from flask import send_from_directory
app = Flask(__name__)
@app.route('/', defaults=dict(filename=None))
@app.route('/<path:filename>', methods=['GET', 'POST'])
def index(filename):
filename = filename or 'index.html'
if request.method == 'GET':
return send_from_directory('.', filename)
return jsonify(request.data)
if __name__ == '__main__':
app.run(debug=1)
@Hamza5
Copy link

Hamza5 commented Apr 29, 2021

I am new to Flask and I don't know most of its functions. That's exactly what I was looking for. Thank you so much for showing us send_from_directory and how to use it.

@ibigbug
Copy link
Author

ibigbug commented Apr 30, 2021

@Hamza5 Thanks for letting me know and glad it helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment