pythondjangodjango-sitemaps

django sitemap DoesNotExist at /sitemap.xml


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


Solution

  • 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.