Kutaiba H Momani
Kutaiba H Momani

Reputation: 123

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

Upvotes: 6

Views: 1543

Answers (3)

Bogdan Kozlovskyi
Bogdan Kozlovskyi

Reputation: 60

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.

Upvotes: 2

hawaiih
hawaiih

Reputation: 121

You can try to add SITE_ID = 1 above INSTALLED_APPS.

Upvotes: 12

slsh1o
slsh1o

Reputation: 41

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

Upvotes: 4

Related Questions