how to add cms.urls integrated in my django application to sitemap.xml

272 Views Asked by At

I have this in my django project. In views.py:

class MediatorViewSitemap(Sitemap):
    changefreq = 'monthly'
    priority = 0.8

    def items(self):
        return Mediator.objects.exclude(photo='')

    def lastmod(self, obj):
        return obj.modified

    static_list =[
        'home',
        'mediators_list',
        'about',
        'faq',
        'pricing',
        'terms',
        'privacy',
        'contact',
    ]

class StaticViewSitemap(Sitemap):
    priority = 0.5
    changefreq = 'daily'

    def items(self):
        return static_list

    def location(self, item):
        return reverse(item)

And this in my urls.py

sitemaps = {
    'mediators': MediatorViewSitemap,
    'static': StaticViewSitemap
}

url(
    r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
    name='django.contrib.sitemaps.views.sitemap'
),

And it generate very well my sitemap.xml

Now I have integrated djangocms to my django project, so I have this url in the same urls.py:

url(r'^blog/', include('cms.urls')),

What I want is to add it to the same sitemap.xml, any suggestion of any tutorial or help from anyone ?

1

There are 1 best solutions below

0
On

Import the CMSSitemap like from cms.sitemaps import CMSSitemap then mix that with your Sitemap classes;

sitemaps = {
    'mediators': MediatorViewSitemap,
    'static': StaticViewSitemap,
    'cmspages': CMSSitemap
}

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

There is a package to extend sitemaps from one of the CMS core dev team as well that may be of use to you; https://github.com/nephila/djangocms-page-sitemap/