Django sitemap.xml throwing Server Error (500) in production

931 views Asked by At

My app is throwing ERROR 500 while accessing example.com/sitemap.xml Additional server configurations = Nginx+Gunicorn+postgres

Here are my files

sitemap.py

from django.contrib.sitemaps import Sitemap
from .models import Post, Status 

class PostSitemap(Sitemap):    
    changefreq = 'daily'
    priority = 0.9

    def items(self):
        return Post.objects.filter(status=0)

    def lastmod(self, obj):
        return obj.created_on

class StatusSitemap(Sitemap):
    changefreq='daily'
    priority = 0.9

    def item(self):
        return Status.objects.filter(status=0)

    def lastmod(self, obj):

url.py

sitemaps = {
    'posts': PostSitemap,
    'status': StatusSitemap
}
urlpatterns = [ path('sitemap.xml/', sitemap, {'sitemaps': sitemaps},
 name='sitemaps'),]

Don't know why is this showing error 500

UPDATE Tarckbacks - enter image description here

1

There are 1 answers

0
Abhijeet Pal On BEST ANSWER

Okay In case someone was dumb enough to repeat this silly mistake like me!

Dear, you have forgotten to add 'django.contrib.sitemaps', in you INSTALLED APPS.