Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Last active August 17, 2017 08:16
Show Gist options
  • Save allenyang79/ede23ef5f41cc7f97a9e8fd137aba54f to your computer and use it in GitHub Desktop.
Save allenyang79/ede23ef5f41cc7f97a9e8fd137aba54f to your computer and use it in GitHub Desktop.
custom flask prefix
# -*- coding: utf-8 -*-
from flask import Flask, request
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
app = Flask(__name__)
app.debug = True
@app.route('/')
def hello_world():
print 'url', request.url
print 'url_root', request.url_root
print 'base_url', request.base_url
print 'host_url', request.host_url
print 'host', request.host
print 'query_string', request.query_string
print 'scheme', request.scheme
print dir(request)
return 'Hello World!'
def simple(env, resp):
resp(b'200 OK', [(b'Content-Type', b'text/plain')])
return [b'Hello WSGI World']
# combine mutli app to uwsgi app.
# in this case. we plan to add prefix for my flask app
app.wsgi_app = DispatcherMiddleware(simple, {'/abc/123': app.wsgi_app})
if __name__ == '__main__':
run_simple('localhost', 5000, app,
use_reloader=True, use_debugger=True, use_evalex=True)
url http://localhost:5000/abc/123/
url_root http://localhost:5000/abc/123/
base_url http://localhost:5000/abc/123/
host_url http://localhost:5000/
host localhost:5000
query_string
scheme http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment