将Django管理员显示时间设置为本地时间? [英] Setting Django admin display times to local time?
问题描述
当我在管理员中看到日期和时间时,它们以UTC显示。我希望它们显示在我的本地时区。我在TIME_ZONE 设置 noreferrer>文档,尽管看起来并不是我想要的。 TIME_ZONE
确定数据库中存储的日期时间的时区,这不是我要设置的时间,我只想本地化
管理员的时区,但不更改它们在数据库级别的保存方式。
When I see dates and times in the admin, they are displayed in UTC. I'd like for them to be displayed in my local timezone. I checked the TIME_ZONE
setting in the docs, though it doesn't look like that is quite what I want. TIME_ZONE
determines the time zone for the datetimes stored in the database, which is not what I want to set -- I just want to localize
the time zones for the admin, but not change how they are saved at the database level.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
从2.1版开始,Django本身不支持此功能。但是 https://github.com/charettes/django-sundial 可能会提供您所需的内容- -这会添加一个 User.timezone
模型字段,以便您可以针对每个用户进行配置。
This isn't supported natively in Django as of 2.1. However https://github.com/charettes/django-sundial may provide what you need -- this adds a User.timezone
model field so that you can configure it per-user.
(此中间件非常简单-只需调用 timezone.activate(zone)
即可更改呈现网站的时区)。
(This middleware is very simple -- under the covers it's just calling timezone.activate(zone)
to change the rendered site's timezone).
这篇关于将Django管理员显示时间设置为本地时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!