When I visit the localhost:8000/sitemap.xml
It shows This XML file does not appear to have any style information associated with it. The document tree is shown below.
The tree
<urlset>
<url>
<loc>http://127.0.0.1:8000/en/product/detail/health-and-care/beauty/cream/dcaad0bb-4e30-4166-b447-508e6ad12ddf/</loc>
<lastmod>2020-11-16</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
</urlset>
Where I expected this tree to be more like this
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://127.0.0.1:8000/en/product/detail/health-and-care/beauty/cream/dcaad0bb-4e30-4166-b447-508e6ad12ddf/</loc>
<lastmod>2020-11-16</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
</urlset>
I have followed the django documentation as well as seen other websites. But every time I get the same result.
Can you please help. How can I remove the XML error
and show my xml like this
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://127.0.0.1:8000/en/product/detail/health-and-care/beauty/cream/dcaad0bb-4e30-4166-b447-508e6ad12ddf/</loc>
<lastmod>2020-11-16</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
</urlset>
settings.py
INSTALED_APPS = [
#
#
"django.contrib.sites",
"django.contrib.sitemaps",
#
#
]
SITE_ID = 1
sitemaps.py
from django.contrib.sitemaps import Sitemap
from django.shortcuts import reverse
from .models import Product
# Inherting the Sitemap class of the sitempas module.
class ProductSitemap(Sitemap):
# These two attributes indicate the change frequency
# and the relevencae in the webiste.
changefreq = 'weekly'
priority = 0.9
def items(self):
# This method return the QuerySet of objects
# to include in the sitemap
products = Product.objects.all()
products = products.prefetch_related('seller_product')
return products
def lastmod(self, obj):
# receives each object returned by items
# and return the last time the object
# was modified.
return obj.updated
urls.py
from django.contrib.sitemaps.views import sitemap
from products.sitemaps import ProductSitemap
sitemaps = {
'products': ProductSitemap
}
urlpatterns = [
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
]