在 heroku 上使用带有 django 的站点地图包

using the sitemap package with django on heroku

在 heroku 上安装站点地图并获取它 运行 显示以下问题。我正在听从以下建议:

https://docs.djangoproject.com/en/1.8/ref/contrib/sitemaps/

并将站点地图放入我的 requirements.txt

然而当执行www.xyz.com/sitemaps.xml时,我得到以下错误:

AttributeError at /sitemap.xml
'function' object has no attribute 'itervalues'


Request Method: GET
Request URL:    http://www.xyx.com/sitemap.xml
Django Version: 1.6.5
Exception Type: AttributeError
Exception Value:    
'function' object has no attribute 'itervalues'
Exception Location: /app/.heroku/python/lib/python2.7/site-packages/django/utils/six.py in itervalues, line 494
Python Executable:  /app/.heroku/python/bin/python
Python Version: 2.7.8
Python Path:    
['/app',
 '/app/.heroku/python/bin',
 '/app/.heroku/python/lib/python2.7/site-packages/setuptools-18.0.1-py2.7.egg',
 '/app/.heroku/python/lib/python2.7/site-packages/pip-7.0.3-py2.7.egg',
 '/app',
 '/app/.heroku/python/lib/python27.zip',
 '/app/.heroku/python/lib/python2.7',
 '/app/.heroku/python/lib/python2.7/plat-linux2',
 '/app/.heroku/python/lib/python2.7/lib-tk',
 '/app/.heroku/python/lib/python2.7/lib-old',
 '/app/.heroku/python/lib/python2.7/lib-dynload',
 '/app/.heroku/python/lib/python2.7/site-packages']

所以这是我在 stettings 中的内容:

INSTALLED_APPS: 'django.contrib.sitemaps'

并在 requirements.txt 中:

sitemap

并在 urls.py 中:

url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemap}, name='django.contrib.sitemaps.views.sitemap'),

问题出在哪里?

就我想使用站点地图的方式而言:

查看其中一些示例的问题之一是我没有定义模型。 运行一切都在 MongoDB。此外,页面是从:访问的,所以有没有一种方法可以使用站点地图,请记住我的浏览量非常少-但有数千页。如何在没有明确模型的情况下最好地自动构建站点地图。

我怀疑是因为没有定义模型,所以我需要生成一个 URL 的列表,与我的观点相对应。

您不需要将其放入 requirements.txt,它是 Django 的一部分,因此已经安装。

错误是因为你只配置了一半;您需要定义一个 Sitemap class 并在 URL 模式

中的字典中引用它