Skip to content

Instantly share code, notes, and snippets.

@jeffgodwyll
Last active December 29, 2015 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgodwyll/eeac379167317b48861d to your computer and use it in GitHub Desktop.
Save jeffgodwyll/eeac379167317b48861d to your computer and use it in GitHub Desktop.
# 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