UnknownTimeZoneError when using RequestContext

女生的网名这么多〃 提交于 2019-12-23 03:16:35

问题


When using Django 1.4, I am getting an UnknownTimeZoneError for America/Chicago when using RequestContext, but it works without it...any ideas?

Error Message

UnknownTimeZoneError at /my_proj/bad_view/
'America/Chicago'

Source

# 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))

回答1:


If you don't care about timezone support you should add USE_TZ = False to your settings.py.

If you want timezone support you should install pytz:

pip install 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.

You should read django's timezone docs to learn how django 1.4 handles timezones.



来源:https://stackoverflow.com/questions/13254409/unknowntimezoneerror-when-using-requestcontext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!