capture client side location in Django

34 views
Skip to first unread message

Salima Begum

unread,
Sep 24, 2020, 9:42:58 PM9/24/20
to django...@googlegroups.com
Hi all,

How to capture client side location in django can any one help to achieve this?


Thank you
~Salima

Stats Student

unread,
Sep 25, 2020, 12:12:15 AM9/25/20
to django...@googlegroups.com
You can read the client's IP address with -

request.META['REMOTE_ADDR'] -- ( not sure how it handles proxies, etc )

then use GeoIP2 to get the location info -

https://docs.djangoproject.com/en/3.1/ref/contrib/gis/geoip2/
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMSz6bnm%3D7AjMNTpR3TowCPZjRPsVfSLTzYk%2Byo5hERmkiYfqw%40mail.gmail.com.

Kasper Laudrup

unread,
Sep 25, 2020, 5:48:32 AM9/25/20
to django...@googlegroups.com
On 25/09/2020 06.10, Stats Student wrote:
> You can read the client's IP address with -
>
> request.META['REMOTE_ADDR'] -- ( not sure how it handles proxies, etc )
>

Proxies should set the X-Forwarded-For header:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

the value of which will then be used in the META dictionary.

Worth noticing that it's trivially possible for any client to set that
header as well and there's no way to reliably get the actual IP address
of the client simply because of how HTTP works.

Of course that's just a variation of "never trust the client" :-)

Kind regards,

Kasper Laudrup

Salima Begum

unread,
Sep 26, 2020, 12:25:19 AM9/26/20
to django...@googlegroups.com
Hi all,

I tried use https://docs.djangoproject.com/en/3.1/ref/contrib/gis/geoip2/ and This particular package requires 
GeoLite2-Country.mmdb.gz 
GeoLite2-City.mmdb.gz  
These databases are not free. We are looking for an open source API or package for our web application. 

I appreciate if someone can share suitable pointers.

Thanks
~Salima


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages