时区“东部标准时间”未被识别

时间:2014-01-05 18:35:26

标签: python django timezone views

我一直收到这个错误:

  

时区“东部标准时间”未被识别

这是代码:

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

2 个答案:

答案 0 :(得分:12)

已安装pytz,错误消失了:

pip install pytz

这可能是仅限Windows的问题,请参阅说明https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TIME_ZONE

答案 1 :(得分:1)

由于我无法看到您的数据,因此很难分辨,但看起来您在某个时区的数据字段/列中有“东部标准时间”。

Python通过IANA/Olson time zones使用the pytz package。所以你的数据在美国东部时间应该有“America / New_York”。