Setting Django admin display times to local time?

前端 未结 4 2231
天命终不由人
天命终不由人 2021-02-14 14:16

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

4条回答
  •  囚心锁ツ
    2021-02-14 14:26

    You can override the template for your change_list.html, change_form.html, etc. and do something like:

    {% extends "admin/change_list.html" %}
    {% load tz %}
    
    {% block content %}
        {% timezone "US/Eastern" %}
            {{ block.super }}
        {% endtimezone %}
    {% endblock %}
    

    Do it with one of those methods:

    • https://docs.djangoproject.com/en/dev/ref/contrib/admin/#admin-overriding-templates
    • https://docs.djangoproject.com/en/dev/ref/contrib/admin/#custom-template-options

提交回复
热议问题