百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

django-easy-timezones

> 后端框架
开源

基于 GeoIP 的 Django 简单时区

199 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

基于 GeoIP 的 Django 简单时区

django-easy-timezones

Easy IP-based timezones for Django (>=1.7) based on MaxMind GeoIP, with IPv6 support.

Quick start

  1. Install django-easy-timezones

    python
    pip install django-easy-timezones
  2. Add "easy-timezones" to your INSTALLED_APPS setting like this:

    python
    INSTALLED_APPS = (
      ...
      'easy_timezones',
    )
  3. Add EasyTimezoneMiddleware to your MIDDLEWARE_CLASSES

    python
    MIDDLEWARE_CLASSES = (
      ...
      'easy_timezones.middleware.EasyTimezoneMiddleware',
    )
  4. (Optionally) Add a path to the MaxMind GeoIP cities databases (direct link because I'm nice) in your settings file:

    python
    GEOIP_DATABASE = '/path/to/your/geoip/database/GeoLiteCity.dat'
    GEOIPV6_DATABASE = '/path/to/your/geoip/database/GeoLiteCityv6.dat'
  5. Enable localtime in your templates.

    python
    {% load tz %}
        The UTC time is {{ object.date }}
    {% localtime on %}
        The local time is {{ object.date }}
    {% endlocaltime %}
  6. Twist one up, cause you're done, homie!

Signals

You can also use signals to perform actions based on the timezone detection.

  1. To hook into the Timezone detection event to, say, save it to the request's user somewhere more permanent than a session, do something like this:

    python
    from easy_timezones.signals import detected_timezone    
    
    @receiver(detected_timezone, sender=MyUserModel)
    def process_timezone(sender, instance, timezone, **kwargs):
        if instance.timezone != timezone:
            instance.timezone = timezone
            instance.save()

Issues· 19 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonautomaticdjangoeasyeasy-timezones

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架