I have a problem with adding alternates attribute to my sitemaps.py
sitemaps.py
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'weekly'
protocol = 'https'
i18n = True
alternates = True
def alternate_hreflangs(self, obj):
return [('en-us', obj.alternative_object_url), ]
def items(self):
return ['index','about', 'contact', 'why', 'product', 'tender-management', 'e-sourcing', 'network', 'faq']
def location(self, item):
return reverse(item)
when I set the alternates = True my sitemap.xml file broke and show a string file
https://example.com/en/weekly0.5https://example.com/en/about/weekly0.5https://example.com/en/contact/weekly0.5
Instead of
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/en/</loc>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://example.com/en/about/</loc>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://example.com/en/contact/</loc>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
I get this problem only when adding the alternates = True my sitemap.xml