2017-03-07 40 views

回答

1

当您使用timezone.now()时,默认使用settings.py中的区域定义,但您可以更改它,请参阅有关selecting the current time zone的文档。

你有3种选择:

  • 中间件
  • 查看
  • 模板

不要忘记安装pytz使用midlleware或视图:pip install pytz。否则,如果你做的模板:

{% load tz %} 

{% timezone "Europe/Paris" %} 
    Paris time: {{ value }} 
{% endtimezone %} 

{% timezone None %} 
    Server time: {{ value }} 
{% endtimezone %}