[Fixed]-Django sitemap : 'module' object has no attribute 'get_urls'

1👍

The error you get is ought to the fact that you are passing inside the sitemaps dictionary, the module PostSiteMap itself instead of the actual PostsSiteMap class (that lives inside the PostSiteMap module).

First of all, your sitemaps should live in a separate file called sitemap.py (this is just a convention and a good pracice). This file should live on the same level as wsgi.py, settings.py etc, because it concerns the sitemap of the whole project (that’s why it’s called sitemap!).

In your views.py (which are defining the PostsSiteMap class) you should right something like this:

# blog/views.py

class PostsSiteMap(Sitemap):
    # your code as is

# This dictionary outside the class definition
SITEMAPS = {
    'post': PostsSiteMap,
}

Now, in your urls.py write these:

# urls.py

from django.conf.urls import url, include
....
from blog.views import SITEMAPS

urlpatterns = [
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': SITEMAPS}, name='django.contrib.sitemaps.views.sitemap')
]
👤nik_m

Leave a comment