Source code for the video. Check the video for the full explanation.

Add these to INSTALLED_APPS:


Define SITE_ID:


Run migrations:

python migrate

Create anywhere in your project:

from django.contrib.sitemaps import Sitemap
from blog.models import Post

class PostSitemap(Sitemap):

    def items(self):
        return Post.objects.all()

Edit the main file:

from django.contrib.sitemaps.views import sitemap
from base.sitemaps import PostSitemap

sitemaps = {
'posts': PostSitemap,

urlpatterns = [
    path('sitemap.xml', sitemap, {'sitemaps': sitemaps},

Define get_absolute_url

The following assumes that you have defined a path for post model in file:

from blog import views as blog_views

path('post/<int:id>/',, name='post'),

In the blog model add get_absolute_url(self):

from django.urls import reverse

class Post(models.Model):

    title = models.CharField(max_length=255, default='')


    def get_absolute_url(self):
        return reverse('post', args=[str(])

Visit /sitemap.xml.

Sitemaps For Static Views

Add this class to the file:

class StaticViewSitemap(Sitemap):

    def items(self):
        return ['about']

    def location(self, item):
        return reverse(item)

Add StaticViewSitemap to the sitemaps dictionary in and make sure that you have a path for the about view:

sitemaps = {
    'posts': PostSitemap,
    'static': StaticViewSitemap, # < here
path('about', base_views.about, name='about'),

Check the official documentation for more configuration options.