gpt4 book ai didi

python - 时区 "Eastern Standard Time"无法识别

转载 作者:太空狗 更新时间:2023-10-29 21:26:42 25 4
gpt4 key购买 nike

我一直收到这个错误:

time zone "Eastern Standard Time" not recognized

代码如下:

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:\Users\Ara\Documents\Sites\kinball\blog\templates\posts\index.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:\Python33\lib\site-packages\django\core\handlers\base.py" in get_response
139. response = response.render()
File "C:\Python33\lib\site-packages\django\template\response.py" in render
105. self.content = self.rendered_content
File "C:\Python33\lib\site-packages\django\template\response.py" in rendered_content
82. content = template.render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in render
140. return self._render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Python33\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Python33\lib\site-packages\django\template\loader_tags.py" in render
123. return compiled_parent._render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in _render
134. return self.nodelist.render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Python33\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Python33\lib\site-packages\django\template\loader_tags.py" in render
62. result = block.nodelist.render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Python33\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Python33\lib\site-packages\django\template\defaulttags.py" in render
305. return nodelist.render(context)
File "C:\Python33\lib\site-packages\django\template\base.py" in render
840. bit = self.render_node(node, context)
File "C:\Python33\lib\site-packages\django\template\debug.py" in render_node
78. return node.render(context)
File "C:\Python33\lib\site-packages\django\template\defaulttags.py" in render
156. len_values = len(values)
File "C:\Python33\lib\site-packages\django\db\models\query.py" in __len__
77. self._fetch_all()
File "C:\Python33\lib\site-packages\django\db\models\query.py" in _fetch_all
854. self._result_cache = list(self.iterator())
File "C:\Python33\lib\site-packages\django\db\models\sql\compiler.py" in results_iter
1096. for rows in self.execute_sql(MULTI):
File "C:\Python33\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
781. cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\util.py" in execute
69. return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\util.py" in execute
53. return self.cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\utils.py" in __exit__
99. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python33\lib\site-packages\django\utils\six.py" in reraise
490. raise value.with_traceback(tb)
File "C:\Python33\lib\site-packages\django\db\backends\util.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 - 时区 "Eastern Standard Time"无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com