django sitemap DoesNotExist at /sitemap.xml

Question:

when i add sitemap to my Django project i got this error ..

DoesNotExist at /sitemap.xml

Site matching query does not exist.

sitemap.py :

from django.contrib.sitemaps import Sitemap
from .models import Homepage


class DynamicSitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.5

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

url.py :

from first_app.sitemaps import DynamicSitemap
from django.contrib.sitemaps.views import sitemap

sitemaps = {'dynamic': DynamicSitemap()}

urlpatterns = [
    path('sitemap.xml', sitemap , {'sitemaps': sitemaps}, name='sitemaps'),
]

settings.py :

INSTALLED_APPS = [

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tinymce',
    'first_app',
    'django.contrib.sitemaps',

]

any help and thanks

enter image description here

Asked By: Kutaiba H Momani

||

Answers:

According to the answer here comment out the ‘django.contrib.sites’ in the settings.py file under INSTALLED_APPS solve this problem.

Answered By: slsh1o

You can try to add SITE_ID = 1 above INSTALLED_APPS.

Answered By: hawaiih

Actually, the answer stated in this article is wrong. To fix this, you just need to add SITE_ID = 1 to your settings.py. That will do the trick.

Answered By: Bogdan Kozlovskyi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.