'How does "alternates" in the Django sitemap framework work?

I am struggling to get the "alternates" attribute to work in the Django sitemap framework.

class StaticViewSitemap(sitemaps.Sitemap):
    priority = 0.5
    changefreq = 'daily'
    i18n = True
    alternates = True

    def items(self):
        return ['index', 'about']

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

The documentation appears to suggest the above i.e. setting i18n and alternates to True. But when I do that, my sitemap is literally a plain test string like this:

http://127.0.0.1:8000/en/daily0.5http://127.0.0.1:8000/en/about/daily0.5http://127.0.0.1:8000/es/daily0.5http://127.0.0.1:8000/es/about/daily0.5

Whereas it should look like so:

<urlset xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9" xmlns: xhtml = "http://www.w3.org/1999/xhtml" >
    <url >
        <loc > http: // 127.0.0.1: 8000/</loc >
        <changefreq > daily < /changefreq >
        <priority > 0.5 < /priority >
    </url >
    <url >
        <loc > http: // 127.0.0.1: 8000/about/</loc >
        <changefreq > daily < /changefreq >
        <priority > 0.5 < /priority >
    </url >
</urlset >

There are two issues:

  1. It doesn't have the correct formatting. What am I doing wrong here?
  2. I don't want the 'en' language prefix for the default language. How do I remove this?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source