【问题标题】:How to change the tz in records stored by the usage of django-auditlog in django admin panel如何在 django 管理面板中使用 django-auditlog 更改存储的记录中的 tz
【发布时间】:2021-03-24 22:43:02
【问题描述】:

我正在使用 django-auditlog 库来存储关于我的一些模型的审计日志。

我注意到,尽管我已经在 settings.py 中定义了时区,但所有包含 DateTimeField 类型字段的模型都以 UTC 时间存储在我的管理面板的日志条目部分中。

这是我的settings.py 部分关于时间和时区配置:

USE_L10N = True
TIME_ZONE = 'Europe/Athens'
USE_TZ = True

如何使日志审核记录位于我定义的时区而不是 UTC?

【问题讨论】:

    标签: django audit-logging django-auditlog


    【解决方案1】:

    我终于找到了我正在寻找的解决方案。

    settings.py 我必须声明以下内容:

    TIME_ZONE = 'Europe/Athens'
    USE_L10N = True
    USE_TZ = False
    class TimezoneMiddleware:
        def __init__(self, get_response):
            self.get_response = get_response
        def __call__(self, request):
            timezone.activate(pytz.timezone('Europe/Athens'))
            return self.get_response(request)
    

    【讨论】:

      猜你喜欢
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      相关资源
      最近更新 更多