Skip to content

Instantly share code, notes, and snippets.

@rduplain
Created April 10, 2012 15:58
Show Gist options
  • Save rduplain/2352388 to your computer and use it in GitHub Desktop.
Save rduplain/2352388 to your computer and use it in GitHub Desktop.
Flask: serving static file from a separate domain
# http://flask.pocoo.org/mailinglist/archive/2012/4/10/serving-static-file-from-a-separate-domain-in-production/
from flask import Flask, url_for
# Uncomment to set server name.
# SERVER_NAME = 'mianos.com'
app = Flask(__name__, static_folder=None)
app.config.from_object(__name__)
app.add_url_rule('/<path:filename>', endpoint='static',
view_func=app.send_static_file, subdomain='static')
@app.route('/')
def index():
return url_for('static', filename='style.css')
if __name__ == '__main__':
app.run(debug=True)
@jamesingham
Copy link

If I use "app.debug = True" and "app.run(host='0.0.0.0', port=5000)", the static content will be given the port 5000 while testing. Is there any way around this?

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