Sitemap in Django 1.10.7

290 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 im my urls.py file i have the following:

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')),
]

After deploying these files, I should be able to see the .xml file at /sitemap.xml but i'm getting a 404 error:

Page not found (404)
    Request Method: GET
        Request URL:    http://xxxxxxxxxxxxxx.co.uk/sitemap.xml/
            Raised by:  cms.views.details
Using the URLconf defined in ames.urls, Django tried these URL patterns, in this order:
    ^admin/
    ^contact/
    ^news/
    ^sitemap.xml$
    ^$
    ^ ^cms_wizard/
    ^ ^(?P<slug>[0-9A-Za-z-_.//]+)/$ [name='pages-details-by-slug']
    ^ ^$ [name='pages-root']
The current URL, /sitemap.xml/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

Any thoughts greatly appreciated.

2

There are 2 answers

2
AudioBubble On BEST ANSWER

try to replace:

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

to

url(r'^sitemap.xml/', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
#                ^^^
1
binpy On

I thought it was a cache issue.

  • Open new incognito window in your browser then open http://xxxxxxxxxxxxxx.co.uk/sitemap.xml without shalsh (/).

OR:

  • Clear cache and then reopen again your http://xxxxxxxxxxxxxx.co.uk/sitemap.xml without shalsh (/).

Don't miss to change: sitemap.xml to sitemap\.xml like this source.