1

I'm integrating Stripe payment for my Django app. One of the required field for payment is the country. My question is how to know the current location of the user? I do not need a map. I just want a country name.

catherine
  • 22,492
  • 12
  • 61
  • 85
  • https://www.google.lv/search?q=ip+to+country+code – Peon Jan 30 '13 at 08:35
  • 1
    see this question http://stackoverflow.com/questions/6747833/how-can-i-find-a-users-country-using-html5-geolocation – Rohan Jan 30 '13 at 08:37
  • If you do not know the answer, do not down vote my question because I'm really serious about this. – catherine Jan 30 '13 at 08:38
  • Why not use the included batteries in Django? Django already has support for the GeoIP databases from MaxMind and has an extremely simple to use API. (see my answer) – bikeshedder Jan 30 '13 at 09:54

1 Answers1

1

Add a form field with a country dropdown and let the user choose.

You could use geoip as a first guess, but that should only be used a the default for such dropdown as the user might be using a proxy.

Edit:

Since you are using Django I would recommend to use the included batteries: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoip/

I would rather NOT use an external service for this. This will slow down your site cause a unneeded depedency.

Example code for a Django view:

from django.contrib.gis.geoip import GeoIP
g = GeoIP()
c = g.country(request.META['REMOTE_ADDR'])
# c.country_code and c.country_name do now contain
# The data you want. Simply pass it to a template,
# form and/or use it for the stripe API.
bikeshedder
  • 7,337
  • 1
  • 23
  • 29
  • I wonder why this got downvoted. It is the correct answer and by using [GeoIP](http://dev.maxmind.com/geoip/geolite) you do not even have to use an external service. Only relying on the IP address is plainly wrong as the user might be using Tor or some other proxy that hides his true IP address. – bikeshedder Jan 30 '13 at 09:36
  • I'm also curious why it's down voted. There are so many people who can't understand. – catherine Jan 30 '13 at 10:24