Last active
December 29, 2015 15:38
-
-
Save jeffgodwyll/eeac379167317b48861d 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
# Snippet 1 | |
########### | |
# Copy the build folder(containing the html files) to a folder in flask's static | |
# directory and serve this way: | |
@app.route('/<dir>/<filename>', defaults={'static': True}) | |
def build_dir(dir='',filename='index.html'): | |
path = join(dir,filename) | |
return app.send_static_file(path) | |
# Alternative | |
@app.route('/<path:path>') | |
def static_html(path): | |
return app.send_static_file(path) # send_static handles mime type | |
# Send from directory might actually be best for this use case for user supplied | |
# path and not send_file or send_static_file | |
app = Flask(__name__, static_url_path='') | |
@app.route('/build/<path:path') | |
def send_build(path): | |
return send_from_directory('build', path) | |
# Another approach | |
@app.route('/<string:page_name>/') | |
def render_static(page_name): | |
return render_template('%s.html' % page_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment