I encountered this issue as well. Between the documentation and the code samples I was looking at, I still couldn't understand why I was seeing this error.
The misread documentation on my part was from https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/:
It may also map to an instance of a Sitemap class (e.g., BlogSitemap(some_var)).
I then looked at the Django source a bit closer. The view is as follows (django.contrib.sitemaps.views.sitemap):
def sitemap(request, sitemaps, section=None, template_name='sitemap.xml'):
maps, urls = [], []
if section is not None:
if section not in sitemaps:
raise Http404("No sitemap available for section: %r" % section)
maps.append(sitemaps[section])
else:
maps = sitemaps.values() # This is where I was seeing the error.
page = request.GET.get("p", 1)
current_site = get_current_site(request)
for site in maps:
try:
if callable(site):
urls.extend(site().get_urls(page=page, site=current_site))
else:
urls.extend(site.get_urls(page=page, site=current_site))
except EmptyPage:
raise Http404("Page %s empty" % page)
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
xml = smart_str(loader.render_to_string(template_name, {'urlset': urls}))
return HttpResponse(xml, mimetype='application/xml')
It then dawned on me that the parameter sitemaps was actually a dictionary of key to sitemap objects, not a sitemap object itself. It's possible that this should have been obvious to me, but it took a bit for me to overcome my mental block.
The full coding sample that I used looks like the following:
sitemap.py file:
from django.contrib.sitemaps import Sitemap
from articles.models import Article
class BlogSitemap(Sitemap):
changefreq = "never"
priority = 0.5
def items(self):
return Article.objects.filter(is_active=True)
def lastmod(self, obj):
return obj.publish_date
urls.py file:
from sitemap import BlogSitemap
# a dictionary of sitemaps
sitemaps = {
'blog': BlogSitemap,
}
urlpatterns += patterns ('',
#...<snip out other url patterns>...
(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
)