Created
January 30, 2012 15:49
-
-
Save rduplain/1705072 to your computer and use it in GitHub Desktop.
Serve a Flask app on a sub-url during localhost development.
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
"Serve a Flask app on a sub-url during localhost development." | |
from flask import Flask | |
APPLICATION_ROOT = '/spam' | |
app = Flask(__name__) | |
app.config.from_object(__name__) | |
@app.route('/') | |
def index(): | |
return 'Hello, world!' | |
if __name__ == '__main__': | |
# Relevant documents: | |
# http://werkzeug.pocoo.org/docs/middlewares/ | |
# http://flask.pocoo.org/docs/patterns/appdispatch/ | |
from werkzeug.serving import run_simple | |
from werkzeug.wsgi import DispatcherMiddleware | |
app.config['DEBUG'] = True | |
# Load a dummy app at the root URL to give 404 errors. | |
# Serve app at APPLICATION_ROOT for localhost development. | |
application = DispatcherMiddleware(Flask('dummy_app'), { | |
app.config['APPLICATION_ROOT']: app, | |
}) | |
run_simple('localhost', 5000, application, use_reloader=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment