pythondjangositemapdjango-cmsdjango-sitemaps

Remove pages from sitemap


I'm using the Django Cms 2.3.5 and I was generating the sitemap like this article from the docs

Now my question is there a easy solution to hide two pages from this sitemap because. I have the 404 and the 500 error in my CMS integrated and I dont want that there are in the sitemap!?

Has somebody an idea?


Solution

  • I would try it this way:

    Create a new class, and override the get_url method of SiteMap class

    class CustomCMSSitemap(CMSSitemap):
        def get_urls(self, *args, **kwargs):
           super(CustomCMSSitemap, self).get_urls(*args, **kwargs)
           //your code here
    

    Here is the source for the class SiteMap

    Instead of adding url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}) into the main urls.py, add url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CustomCMSSitemap}})