Skip to main content
 首页 » 编程设计

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

2024年10月24日38grandyang

在 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 中:

站点地图

在 urls.py 中:

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

问题出在哪里?

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

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

我怀疑由于没有定义模型而引起混淆,因此我需要生成一个与我拥有的 View 相对应的 URL 列表。

请您参考如下方法:

你不需要把它放在 requirements.txt 中,它是 Django 的一部分,所以已经安装了。

错误是因为你只做了一半的配置;你需要定义一个 Sitemap class并在您的 URL 模式中引用字典中的内容