我不断收到此错误:
时区"东部标准时间"无法识别
这是代码:
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(IndexView, self).get_context_data(**kwargs)
"""Return the last five published posts."""
context['latest_post_list'] = Post.objects.order_by('-pub_date')[:5]
context['archives'] = Post.objects.datetimes('pub_date', 'month', order='DESC')
return context;
在我的模板中:
{% for archive in archives %}
<li><a href="#">{{ archive.month }} {{ archive.year }}</a></li>
{% endfor %}
在我的设置中:
TIME_ZONE = 'America/Montreal'
我想做的是建立某种存档系统。在可以获得不同月份和年份的地方,有任何帖子。
Environment:
Request Method: GET
Request URL: http://localhost:8000/blog/
Django Version: 1.6.1
Python Version: 3.3.3
Installed Applications:
('django_admin_bootstrapped.bootstrap3',
'django_admin_bootstrapped',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'localflavor',
'reversion',
'autoslug',
'blog',
'acpkinballmanageleague',
'acpkinballmanageteams',
'acpkinballmanageevents',
'acpkinballmanagemembers')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Template error:
In template C:UsersAraDocumentsSiteskinballblogtemplatespostsindex.html, error at line 55
time zone "Eastern Standard Time" not recognized
45 : <nav class="tags">
46 :
47 : </nav>
48 : </div>
49 :
50 : <!-- Archives -->
51 : <nav class="widget">
52 : <h4>Archives</h4>
53 : {% if latest_post_list %}
54 : <ul class="categories">
55 : {% for archive in archives %}
56 : <li><a href="#">{{ archive.month }} {{ archive.year }}</a></li>
57 : {% endfor %}
58 : </ul>
59 : {% endif %}
60 : </nav>
61 :
62 : <!-- Tweets-->
63 : <div class="widget">
64 : <h4>Twitter</h4>
65 : <ul id="twitter-blog"></ul>
Traceback:
File "C:Python33libsite-packagesdjangocorehandlersbase.py" in get_response
139. response = response.render()
File "C:Python33libsite-packagesdjangotemplateresponse.py" in render
105. self.content = self.rendered_content
File "C:Python33libsite-packagesdjangotemplateresponse.py" in rendered_content
82. content = template.render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in render
140. return self._render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in _render
134. return self.nodelist.render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in render
840. bit = self.render_node(node, context)
File "C:Python33libsite-packagesdjangotemplatedebug.py" in render_node
78. return node.render(context)
File "C:Python33libsite-packagesdjangotemplateloader_tags.py" in render
123. return compiled_parent._render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in _render
134. return self.nodelist.render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in render
840. bit = self.render_node(node, context)
File "C:Python33libsite-packagesdjangotemplatedebug.py" in render_node
78. return node.render(context)
File "C:Python33libsite-packagesdjangotemplateloader_tags.py" in render
62. result = block.nodelist.render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in render
840. bit = self.render_node(node, context)
File "C:Python33libsite-packagesdjangotemplatedebug.py" in render_node
78. return node.render(context)
File "C:Python33libsite-packagesdjangotemplatedefaulttags.py" in render
305. return nodelist.render(context)
File "C:Python33libsite-packagesdjangotemplatebase.py" in render
840. bit = self.render_node(node, context)
File "C:Python33libsite-packagesdjangotemplatedebug.py" in render_node
78. return node.render(context)
File "C:Python33libsite-packagesdjangotemplatedefaulttags.py" in render
156. len_values = len(values)
File "C:Python33libsite-packagesdjangodbmodelsquery.py" in __len__
77. self._fetch_all()
File "C:Python33libsite-packagesdjangodbmodelsquery.py" in _fetch_all
854. self._result_cache = list(self.iterator())
File "C:Python33libsite-packagesdjangodbmodelssqlcompiler.py" in results_iter
1096. for rows in self.execute_sql(MULTI):
File "C:Python33libsite-packagesdjangodbmodelssqlcompiler.py" in execute_sql
781. cursor.execute(sql, params)
File "C:Python33libsite-packagesdjangodbbackendsutil.py" in execute
69. return super(CursorDebugWrapper, self).execute(sql, params)
File "C:Python33libsite-packagesdjangodbbackendsutil.py" in execute
53. return self.cursor.execute(sql, params)
File "C:Python33libsite-packagesdjangodbutils.py" in __exit__
99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:Python33libsite-packagesdjangoutilssix.py" in reraise
490. raise value.with_traceback(tb)
File "C:Python33libsite-packagesdjangodbbackendsutil.py" in execute
53. return self.cursor.execute(sql, params)
Exception Type: DataError at /blog/
Exception Value: time zone "Eastern Standard Time" not recognized
安装pytz
,错误消失:
pip install pytz
这可能是仅限 Windows 的问题,请参阅注释 https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TIME_ZONE。
这
真的很难说,因为我看不到您的数据,但看起来您在时区的数据字段/列中有"东部标准时间"。
Python 通过 pytz 包使用 IANA/Olson 时区。 因此,您的数据应具有美国东部时间的"美国/New_York"。