Django IP2Location Time Zone package enables you easily display your website visitor the time baased on their geo location derived from the IP address. This package uses IP2Location Web Service for IP lookup and time zone information.
- Python 2.7 and above.
- Django 1.11 and above.
- IP2Location Web Service API Key. You can get a trial API key from IP2Location.com.
-
Install this package from PyPI:
pip install django-ip2location-timezone
-
Add "ip2location_timezone" to your INSTALLED_APPS setting in settings.py:
INSTALLED_APPS = ( ... 'ip2location_timezone', )
-
Add "IP2locationTimezoneMiddleware" to your MIDDLEWARE_CLASSES in settings.py:
MIDDLEWARE_CLASSES = ( ... 'ip2location_timezone.middleware.IP2locationTimezoneMiddleware', )
-
Add your IP2Location Web Service API Key in settings.py:
IP2LOCATION_API_KEY = 'YOUR_API_KEY'
-
In your template, add the following code to display the user time zone and current time:
{% load tz %} {% localtime on %} {% get_current_timezone as TIME_ZONE %} Your timezone is {{ TIME_ZONE }}.<br/><br/> It is {% now "DATETIME_FORMAT" %} {% endlocaltime %}
Email: [email protected].