Adding a sitemap to Django 1.10.7

256 views Asked by At

I'm having issues getting the Django setup to generate a sitemap for me.

I have added the following to my settings file

'django.contrib.sites',
'django.contrib.sitemaps',

and in my urls file I have the following:

from django.conf.urls import include, url
from django.contrib import admin

from ames import views

from cms.sitemaps import CMSSitemap

admin.autodiscover()

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/', include('contact.urls')),
url(r'^news/', include('news.urls')),
url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^$', views.home),
url(r'^', include('cms.urls')),
]

When deploying these amends I get the following error on the site:

TypeError at /sitemap.xml/
view must be a callable or a list/tuple in the case of include().

Any thoughts would be most welcome.

Amended urls.py file:

from django.conf.urls import include, url
from django.contrib import admin
from cms.sitemaps import CMSSitemap
from django.contrib.sitemaps.views import sitemap
from ames import views

admin.autodiscover()

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/', include('contact.urls')),
url(r'^news/', include('news.urls')),
url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^$', views.home),
url(r'^', include('cms.urls')),
]
1

There are 1 answers

11
AudioBubble On

try it:

from django.contrib.sitemaps.views import sitemap

# you code
    url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),

and remove

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

all information for the solution is in error view must be a callable or a list/tuple in the case of include()