Created
June 24, 2015 06:07
-
-
Save ibigbug/c6f00f31160ac8313ccf to your computer and use it in GitHub Desktop.
Very simple static folder server using Flask
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.