django sitemap DoesNotExist at /sitemap.xml
Asked Answered
M

3

6

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

Merrymaking answered 15/11, 2019 at 17:54 Comment(8)
Please show your folder structure. Where is this url.py stored?Fionnula
in project folder first_project/urls.pyMerrymaking
Please show your folder structure.Fionnula
this is screenshot for structure in photo filebin.net/mlf7cyme2j8ld0e5/e.png?t=oqocm3nmMerrymaking
my file in first_project/urls.pyMerrymaking
If this is a project-level urls.py it is supposed to have other urlpatterns like homepage and so on. Does it? Do you have ROOT_URLCONF defined? Does any other url work?Fionnula
this is the full code in urls.py file and yes the other urls work fine take a look please filebin.net/iqojfkrjx93audi6/urls.py?t=kij53hdqMerrymaking
Possible duplicate of Site matching query does not existFionnula
S
2

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.

Scuba answered 27/2, 2023 at 19:8 Comment(0)
B
12

You can try to add SITE_ID = 1 above INSTALLED_APPS.

Barstow answered 17/7, 2020 at 15:1 Comment(0)
G
4

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

Greywacke answered 3/4, 2020 at 18:9 Comment(0)
S
2

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.

Scuba answered 27/2, 2023 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.