Create Static Sitemaps In Django

Create Static Sitemaps In Django

A sitemap is a xml file which tells search engines about the pages available in your website which can be crawled. Django has inbuilt functionality for generating sitemap.xml file. It automates the creation of sitemaps based on your models.

  1. Add Sitemap To installed Apps
  2. Create Sitemap For Static View
  3. Add Sitemap to Urls
  4. Check Sitemap Url

Add Sitemaps To installed Apps

To use django sitemaps first of all you have to add it as installed app in django project settings. This will look like as follows:

Create Sitemap For Static View

Now we will create a file, in which we will write sitemaps views. Sitemaps classes are must be inherited from django.contrib.sitemaps it can be placed anywhere in your codebase. To create a and add the following code to it.

Add Sitemap to Urls

After creating sitemap view in file now we have to add sitemap views to, you can add in app level or in project level here i am adding it in app level

Check Sitemap Url

After that run django using python runserver and navigate to url localhost:8000/sitemap.xml, it will automatically generate sitemap for our privacy static page as you can see in below gist code.

Leave a Comment