Django站点地图在之前的服务器上运行良好,在我的开发环境中运行良好,但在新服务器上的生产中断,包括:
ValidationError:[u'Unknown timezone'] (下面的追溯)。尝试从管理员访问我们的某个模型时,我也遇到了类似的错误。
更新:
追踪中的路径build / bdist.linux-x86_64 / egg / timezones让我觉得有些奇怪的路径正在发生。原来有人从另一台服务器复制了一堆东西而不是正确的pip安装。我删除了一些旧的libs,修复了virtualenv默认路径,并点了安装的django-timezones。一切都很顺利。离开这个以防万一对任何人都有帮助。
站点地图文档没有提及有关时区配置或依赖项的任何内容: https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/
服务器的时区被正确设置为America / Los_Angeles,我在settings.py中设置了相同的内容我不知道还有什么可以在这里查看而谷歌没有任何结果。
我在urls.py中的SiteMaps定义中引用了8个模型,但是只有一个BlogSiteMap导致破损(如果我将其断开,那么断点停止,但我在站点地图中没有博客帖子。它包括:
class BlogSitemap(Sitemap):
changefreq = "weekly"
priority = 0.7
def items(self):
return Post.objects.filter(status=2).order_by('-modified')
def lastmod(self, obj):
return obj.modified
博客文章模型是这样的(为了简洁而略微编辑)
class Post(models.Model):
"""Post model."""
title = models.CharField(_('title'), max_length=200)
slug = models.SlugField(_('slug'), unique_for_date='publish')
author = models.ForeignKey(User, blank=True, null=True)
body = models.TextField(_('body'))
tease = models.TextField(_('tease'), blank=True)
status = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=2)
allow_comments = models.BooleanField(_('allow comments'), default=True)
fp_show = models.BooleanField('Show on homepage',default=False)
order = models.IntegerField(blank=True, null=True)
publish = models.DateTimeField(_('publish'),default=datetime.now())
created = models.DateTimeField(_('created'), auto_now_add=True)
modified = models.DateTimeField(_('modified'), auto_now=True)
categories = models.ManyToManyField(Category, blank=True)
tags = TagField()
objects = PublicManager()
def __unicode__(self):
return u'%s' % self.title
@permalink
def get_absolute_url(self):
return ('blog_detail', None, {
'year': self.publish.year,
'month': self.publish.strftime('%b').lower(),
'day': self.publish.day,
'slug': self.slug
})
使用: Django 1.3 Python 2.7 RHEL 5.7
感谢。
Traceback (most recent call last):
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/contrib/sitemaps/views.py", line 39, in sitemap
urls.extend(site().get_urls(page=page, site=current_site))
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/contrib/sitemaps/__init__.py", line 75, in get_urls
for item in self.paginator.page(page).object_list:
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
self._result_cache.append(self._iter.next())
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/query.py", line 286, in iterator
obj = model(*row[index_start:aggregate_start])
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/base.py", line 297, in __init__
setattr(self, field.attname, val)
File "/home/username/virtualenvs/kdmc/lib/python2.7/site-packages/django/db/models/fields/subclassing.py", line 99, in __set__
obj.__dict__[self.field.name] = self.field.to_python(value)
File "build/bdist.linux-x86_64/egg/timezones/fields.py", line 43, in to_python
return coerce_timezone_value(value)
File "build/bdist.linux-x86_64/egg/timezones/utils.py", line 34, in coerce_timezone_value
raise ValidationError("Unknown timezone")
ValidationError: [u'Unknown timezone']
答案 0 :(得分:0)
请参阅上面的更新:部分 - 这是由旧安装的库和virtualenv中的错误路径引起的一系列冲突。