Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fix for Django on passenger_wsgi not routing POST request on A2 servers. Simply replace the automatically generated with this version and change the the two instances of 'projectname' to the name of the folder in which the and reside.
Post request dont work on Djano apps on A2 hosted servers. This replacement ''
has fixed the issue for me. Works with Python 3.5 with Django 1.11, 2.0, 2.1, 2.2 and Python 3.7 with Django 3.0.
# Keep this empty
class PassengerPathInfoFix(object):
Sets PATH_INFO from REQUEST_URI since Passenger doesn't provide it.
def __init__(self, app): = app
def __call__(self, environ, start_response):
from urllib.parse import unquote
request_uri = unquote(environ['REQUEST_URI'])
script_name = unquote(environ.get('SCRIPT_NAME', ''))
offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0
environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]
return, start_response)
# Replace projectname with the name of the main folder containing and
import projectname.wsgi
application = projectname.wsgi.application
application = PassengerPathInfoFix(application)

This comment has been minimized.

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