Django sitemap.xml shows plain text

22 views Asked by At

I have added sitemaps following Django 2.0 (I cannot upgrade for now) official documentation. When accessing my production site I get all the correct links with dates but as plaintext, without xml formatting. The google search console is not accepting this format.

My sitemap.py code:

from blog.models import Post
from django.contrib.sitemaps import Sitemap

from courses.models import Course, Interview, Lesson


class PostSitemap(Sitemap):
    changefreq = 'weekly'
    priority = 0.9

    def items(self):
        return Post.objects.all()

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

My urls.py code:

path(
    "sitemap.xml",
    sitemap,
    {"sitemaps": {
                    "courses": CourseSitemap,
                    "posts": PostSitemap,
                    "lessons": LessonSitemap,
                    "podcasts": InterviewSitemap,
                  }},
    name="django.contrib.sitemaps.views.sitemap",
),

enter image description here

How can I change it to XML format?

1

There are 1 answers

0
Hvitis On

The sitemap.xml was showing correctly in Chrome but not in FireFox....

enter image description here