Skip to main content

Support HTTP "Forwarded" header in your Django applications

Project description



Support HTTP "Forwarded" header in your Django applications.

This middleware for Django adds support for the Forwarded header which is standardized by Internet Engineering Task Force (IETF) in RFC 7239 and summarized in Mozilla Developer Network (MDN) article of the same name. This header is used by many reverse HTTP proxies to pass client identification details (such as IPv4 or IPv6) to the backend application.


Install the middleware with your favorite Python package manager


$ pip install django-forwarded


$ pipenv install django-forwarded



Add the middleware to Django's MIDDLEWARE setting.

    ... # some middlewares
    ... # more middlewares


You can configure Django-Forwarded by adding appropriate variable to your Django application configuration file.


Just specify a list of trusted proxies with the TRUSTED_PROXY_LIST variable in the file. This is the recommended way to specify the proxies.



Just specify the number of trusted proxies with the TRUSTED_PROXY_DEPTH variable. This is useful when you have no control over them and their IP(s) might change frequently over the lifetime of your application.

TRUSTED_PROXY_DEPTH = 2  # trusts maximum of 2 proxies

Note: It is not secure as secure as specifying a list.

Access client IP

The middleware identifies the correct client IP from the user supplied configuration and the header received from the proxies. This information is then placed in the request.META['REMOTE_ADDR'] field.

def some_function(request):


To execute the included test suit, run the following commands in a terminal:

$ cd <path to the django-forwarded>
$ pipenv shell  # opens a shell in dev environment
$ DJANGO_SETTINGS_MODULE=tests.settings python3 -m unittest  # run the tests

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Django-Forwarded, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size Django-Forwarded-0.0.2.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page