4

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

Ivan Starostin
  • 8,034
  • 5
  • 18
  • 35

2 Answers2

5

You can try to add SITE_ID = 1 above INSTALLED_APPS.

Monolith
  • 950
  • 11
  • 25
hawaiih
  • 51
  • 1
  • 3
3

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

slsh1o
  • 46
  • 3