Skip to content

Instantly share code, notes, and snippets.

@Tukki
Last active December 19, 2015 10:49
Show Gist options
  • Save Tukki/5943755 to your computer and use it in GitHub Desktop.
Save Tukki/5943755 to your computer and use it in GitHub Desktop.
flask with static file, but not css/js... temporary, in development
http://stackoverflow.com/questions/13706382/how-to-get-static-files-in-flask-without-url-forstatic-file-name-xxx
You can Setup your own route to serve static
files. Add this method and update the static path director in the send_from_directory method and your img tag should work.
@app.route('/pic/<path:filename>')
def send_pic(filename):
return send_from_directory('/path/to/static/files', filename)
For a production app however, you should setup your server to serve static files directly.
It would be much faster and use less server resources, but for a few users it shouldn't be a problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment