0

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')),
]
Keith Riches
  • 63
  • 1
  • 8

1 Answers1

0

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()

Brown Bear
  • 19,655
  • 10
  • 58
  • 76
  • That just throws out an error: NameError at /sitemap.xml/ name 'CMSSitemap' is not defined – Keith Riches Sep 01 '17 at 13:46
  • did you remove `from cms.sitemaps import CMSSitemap` if yes = why? or some where you don't add this import – Brown Bear Sep 01 '17 at 13:47
  • Im a little confused should it read as follows: 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')), ] – Keith Riches Sep 01 '17 at 13:59
  • Done, im very new to all of this – Keith Riches Sep 01 '17 at 14:05
  • no problem, your urls code looks fine for the your last error, please, add full error stack, and may be it better to create new question, but first try to add new full error stack. – Brown Bear Sep 01 '17 at 14:12
  • So i tried it again as per code supplied, its just giving me a 404 error now – Keith Riches Sep 01 '17 at 14:33
  • sorry, need more details, i can't understand – Brown Bear Sep 01 '17 at 14:37
  • We were able to deal with the first problem, and i think need more details full stack of your action and results for your new trouble. – Brown Bear Sep 01 '17 at 14:40
  • Yes it did resolve the first issue i had, how do i go about providing you with this information? – Keith Riches Sep 01 '17 at 15:16
  • as i think simple way is new question, with your current code and full new error stack. – Brown Bear Sep 01 '17 at 15:26
  • As per request, I have opened up a new question here: – Keith Riches Sep 04 '17 at 08:49