Skip to main content

GeoIP based redirection middleware

Project description

[![Build Status](](


![World Map](

GeoIP based redirection is awesome and achieving it isn't too hard either. I wrote this middleware
to ensure that my website would get redirected properly with regards to the location of the user
accessing the website.

## Usage:

Add the middleware in your settings file:


Also add `django_geoip_redirection` to INSTALLED APPS:


## Customization:

# Change the array for extension as per country you
# have to support
if request.path[:4] in ["/en/", "/nl/", "/in/"]:
return None

if 'HTTP_X_FORWARDED_FOR' in request.META:
ip_address = request.META['REMOTE_ADDR']
# get country name using Maxmind database.
# Now, just match and redirect.
# Likewise, replace the name of country to match and redirect.
country = get_country_request(ip_address)
if country == "India":
return HttpResponseRedirect('/in/')
elif country == "Netherlands":
return HttpResponseRedirect('/nl/')
return HttpResponseRedirect('/en/')
return None


You would also need to place the `GeoIP.dat.dat` present inside the data folder to
your project root directory.

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_geoip_redirection, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size django_geoip_redirection-0.1.3.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page