I did this long time ago and here is what i did...
SITE_ID = 1
# Application definition
INSTALLED_APPS = [
# ...
'django.contrib.sites',
'django.contrib.sitemaps',
]
run migration i.e.
>>> py manage.py migrate OR python manage.py migrate
after this step, sites application will be in sync with the database.
create a file sitemaps.py in your blog application. Your sitemap.py seems okay to me.
update your main project urls.py file
....
from django.contrib.sitemaps.views import sitemap
from blog.sitemaps import BlogPostsSitemap
sitemaps = {
'posts' : BlogPostsSitemap,
}
urlpatterns = [
....
path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
]
lets try...