0

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'),
]
Debopriyo Das
  • 135
  • 2
  • 15
  • This is browser web view, you can see actual xml by looking into page source -> view page source ( CTRL+U on chrome) – iklinac Nov 16 '20 at 10:09
  • @KlausD. question linked is related to java facelets and not sitemap xml which does not need style – iklinac Nov 16 '20 at 10:15
  • @iklinac The "error" (which is in reality just a notice by the browser) is totally unrelated to the server and its technology. It is only related to content type delivered and the browser used. – Klaus D. Nov 16 '20 at 10:20
  • @KlausD. yes I got the answer thank you. – Debopriyo Das Nov 16 '20 at 10:28

0 Answers0