Skip to content

Instantly share code, notes, and snippets.



Last active Dec 24, 2015
What would you like to do?
Python wsgi script to dispatch request based on request header

WSGI Script to dispatch request based on request header


pip install flask paste



This will serve all POST requests from backend_app and all other requests from Flask app.

TL;DR read atleast the code luke

# This is example script to show how to dispatch wsgi request based on request header
from flask import Flask
from paste import proxy # Using to proxy requests to remote server
class RequestMethodDispatcher(object):
def __init__(self, main_app, config):
self.main_app = main_app
self.config = config
def get_application(self, environ):
return self.config.get(
environ['REQUEST_METHOD'], self.main_app
def __call__(self, environ, start_response):
app = self.get_application(environ)
return app(environ, start_response)
app = Flask(__name__, static_folder='app', static_url_path='')
backend_app = proxy.make_proxy(
None, '', allowed_request_methods='POST')
app.wsgi_app = RequestMethodDispatcher(app.wsgi_app, {
'POST': backend_app,
if __name__ == "__main__":'', 5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment