使用RequestContext时UnknownTimeZoneError [英] UnknownTimeZoneError when using RequestContext
问题描述
当使用Django 1.4时,在使用RequestContext时,我将获得 America / Chicago
的 UnknownTimeZoneError
没有...任何想法?
When using Django 1.4, I am getting an UnknownTimeZoneError
for America/Chicago
when using RequestContext, but it works without it...any ideas?
错误消息
UnknownTimeZoneError at /my_proj/bad_view/
'America/Chicago'
来源
# This works
def good_view(request):
data = {}
return render_to_response('mytemplate.html',
data)
# This doesn't
def bad_view(request):
data = {}
return render_to_response('mytemplate.html',
data,
context_instance=RequestContext(request))
推荐答案
如果您不关心时区支持,您应该添加 USE_TZ = False
到您的 settings.py
。
If you don't care about timezone support you should add USE_TZ = False
to your settings.py
.
如果你想要时区支持,你应该安装 pytz
:
If you want timezone support you should install pytz
:
pip install pytz
我相信错误是由django获得 America / Chicago
来自请求的模板,但django的有限时区数据没有这个时区。如果安装了
pytz
,错误将消失。
I believe the error is caused by django getting America/Chicago
in the template from the request, but django's limited timezone data doesn't have this timezone. The error will go away if pytz
is installed.
您应该阅读 django的时区docs 了解django 1.4如何处理时区。
You should read django's timezone docs to learn how django 1.4 handles timezones.
这篇关于使用RequestContext时UnknownTimeZoneError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!