I would like to redirect my users to specific location areas in my website, by detecting their location from their IP address.
What would be the best way to achieve this under Django 1.1.1 ?
Thanks
Edit: I want city based locationing on europe.
The first thing we have to do is start a project and start an app inside the project and follow the steps given below. Steps to get the IP address of the user: Step 1- Define two functions in views.py which will store the IP address and show it as an output. Step 2- Changes in urls.py to call the function.
In order to perform IP-based geolocation, the GeoIP2 object requires the geoip2 Python library and the GeoIP Country and/or City datasets in binary format (the CSV files will not work!).
Test website Geolocation using VPN A virtual private network (VPN) proxy server can make it look like the system is in a different location than its actual one. This is a good thing as far as our use case of geolocation testing is concerned. You open a VPN, change location to a specific country and start testing.
GeoDjango looks like it will suit your needs. I'm not sure exactly how you would want to direct users, but using the GeoIP API, you can do something like:
from django.contrib.gis.utils import GeoIP g = GeoIP() ip = request.META.get('REMOTE_ADDR', None) if ip: city = g.city(ip)['city'] else: city = 'Rome' # default city # proceed with city
The Docs explain things in great detail; I would take a moment to read through them thoroughly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With