Please enable JS

Blog

How to add https in django sitemap

Published on May 26, 2017, 12:33 a.m.

How can we add https to sitemap generated url in Django.

We just need to use property called protocol.

from django.contrib.sitemaps import Sitemap
from blog.models import Entry
from django.contrib.sites.models import Site

class BlogSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5
    protocol = "https"

    def get_urls(self, site=None, **kwargs):
        site = Site(domain='foo.com', name='foo.com')
        return super(BlogSitemap, self).get_urls(site=site, **kwargs)

    def items(self):
        return Entry.objects.filter(is_draft=False)

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