Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django sitemap: 'module' object has no attribute 'values'

Tags:

django

sitemap

I follow the description on the http://docs.djangoproject.com/en/1.2/ref/contrib/sitemaps/

I from django.contrib import sitemaps add this line

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

to URLconf

make file sitemap.py with:

from django.contrib.sitemaps import Sitemap
from blog.models import Post

class BlogSitemap(Sitemap):
    changefreq = 'monthly'
    priority = 0.5

    def items(self):
        return Post.objects.all()

    def lastmod(self, obj):
        return obj.date

at this address http://127.0.0.1:8000/sitemap.xml I get an error:

Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/site-packages/django/contrib/sitemaps/views.py" in sitemap
  33.         maps = sitemaps.values()

Exception Type: AttributeError at /sitemap.xml
Exception Value: 'module' object has no attribute 'values'

Anyone can help me?

like image 556
Kubas Avatar asked Feb 14 '11 19:02

Kubas


1 Answers

You missed a step - look at the example in the documentation.

Instead of importing the sitemaps module in your urls.py, import your BlogSitemap class, then create a sitemaps dictionary:

sitemaps = {'blog': BlogSitemap}
like image 119
Daniel Roseman Avatar answered Oct 14 '22 01:10

Daniel Roseman