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

Release history Release notifications

This version
History Node


History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django_geoip_redirection-0.1.3.tar.gz (3.9 kB) Copy SHA256 hash SHA256 Source None Jul 5, 2014

Supported by

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