I ran into this problem. Between the documentation and the code samples that I was looking at, I still could not understand why I saw this error.
The wrong documentation for me was from https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/ :
It can also display an instance of the Sitemap class (e.g. BlogSitemap (some_var)).
Then I looked at the source of Django a little 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()
Then it became clear to me that the sitemaps parameter is actually a dictionary of the key to Sitemap objects, and not a sitemap object. Perhaps this was obvious to me, but it took me a bit to overcome my mental block.
The full coding example that I used is as follows:
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
johncosta
source share