First you need an IP to LOCATION service to get the IP's corresponding location. Whenever you have that service (or database based lookup algorithm) then you could do this:
# got from here: http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
def get_ip_location(ip):
# here you need to invoke a IP to location service, or implement your own.
# It's not that hard. Start here: http://stackoverflow.com/questions/4179000/best-way-to-detect-country-location-of-visitor
pass
def index(request):
ip = get_client_ip(request)
location = get_ip_location(ip)
if location == 'usa':
return redirect('http://usa.abc.com')
elif location == 'japan':
return redirect('http://jpn.abc.com')
# you get the idea
else:
return redirect('http://global.abc.com')