Skip to main content

Django IP2Location Time Zone

Django IP2Location Time Zone package enables you easily display your website visitor the time based on their geo location derived from the IP address. This package uses IP2Location.io API for IP lookup and time zone information.

Requirements

  1. Python 2.7 and above.

  2. Django 5.1 and above.

  3. IP2Location.io API Key. You can get a trial API key from IP2Location.io.

    Note: The time zone information is only available with IP2Location.io API Plus plan and above.

Quick Start

  1. Install this package from PyPI:

    pip install django-ip2location-timezone
    
  2. Add "ip2location_timezone" to your INSTALLED_APPS setting in settings.py:

    INSTALLED_APPS = (
      ...
      'ip2location_timezone',
    )
    
  3. Add "IP2locationTimezoneMiddleware" to your MIDDLEWARE in settings.py:

     MIDDLEWARE = (
       ...
       'ip2location_timezone.middleware.IP2locationTimezoneMiddleware',
     )
    
  4. Add your IP2Location.io API API Key in settings.py:

    IP2LOCATION_API_KEY = 'YOUR_API_KEY'
    
  5. 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 %}
    

Upgrading to 2.0.0

Version 2.0.0 contains breaking changes. Please read this section before upgrading from 1.x.

Breaking changes

  • IP2Location.io API replaces the IP2Location Web Service. The plugin now queries the IP2Location.io API. The API key setting name is unchanged (IP2LOCATION_API_KEY), but you will likely need to get a new API key from IP2Location.io and update its value.
  • Dropped support for Django 1.11 and 2.2. Supported versions are now Django 5.1 and 6.0.

Behavior changes

  • API errors no longer raise exceptions. If the lookup fails (timeout, invalid key, quota exceeded, malformed response), the fields fall back to their default values.

  • Request fields now have default values. The following fields are always present on the request object:

    Field Default
    country_code NO_DATA
    country_name NO_DATA
    region_name NO_DATA
    city_name NO_DATA
    latitude NO_DATA
    longitude NO_DATA
    zip_code NO_DATA
    time_zone NO_DATA
    olson_time_zone PLAN_NOT_SUPPORTED
    current_time PLAN_NOT_SUPPORTED
    gmt_offset PLAN_NOT_SUPPORTED
    is_dst PLAN_NOT_SUPPORTED

Upgrade steps

  1. Upgrade the package:

    pip install --upgrade django-ip2location-timezone
    
  2. Replace your API key in settings with a key from IP2Location.io:

    IP2LOCATION_API_KEY = "your-ip2location-io-api-key"
    
  3. If your code checks for missing or None field values, update it to handle the new defaults.

If you need to stay on the old behavior for now, pin the previous version:

pip install "django-ip2location-timezone<2.0"

Support

Email: support@ip2location.com.

URL: https://www.ip2location.com

Metadata

Release files for django-ip2location-timezone 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ip2location-timezone 2.0.0
File Size Uploaded Provenance Actions
django_ip2location_timezone-2.0.0.tar.gz 5.6 kB Without provenance Details for django_ip2location_timezone-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-ip2location-timezone 2.0.0
File Interpreter ABI Platform Actions
django_ip2location_timezone-2.0.0-py3-none-any.whl Python 3 none any Details for django_ip2location_timezone-2.0.0-py3-none-any.whl

Total release size: 11.7 kB

Release files / django_ip2location_timezone-2.0.0.tar.gz

Download URL django_ip2location_timezone-2.0.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4c4701529b07ee4a9c6efa6b8f587eb0c8cd721fbbd52c5b4b23785f329c1f8a
BLAKE2b-256 checksum
How to use checksums
b4b9e928c363b4622d688af442245a91eb15405431d2e92e41d51a147c7aa104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / django_ip2location_timezone-2.0.0-py3-none-any.whl

Download URL django_ip2location_timezone-2.0.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67250c9a9f0f0770055e887046c01fe4fe2b1cb2965f6ea5bac6718aaa2e8274
BLAKE2b-256 checksum
How to use checksums
f218f05d8e9756872b345f2a84f3095c095f7cc0fcea4d2709363576206dc82c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for django-ip2location-timezone 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page