Engineer in Tokyo

Django Sitemap Framework

Using the Django sitemap framework is so easy it's almost no work at all. Just make a sitemap object and add it to the sitemap in The sitemap framework calls items() in your Sitemap to get the list of objects to put in the sitemap and then calls get_absolute_url() on each object.

from django.db import models
class Entry(models.Model):
    def get_absolute_url(self):
        return ...

from django.contrib.sitemaps import Sitemap
from import Entry

from django.contrib.sitemaps import Sitemap
from import Entry

class BlogSitemap(Sitemap):
    priority = 0.5

    def items(self):
        return Entry.objects.filter(is_draft=False)

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

    # changefreq can be callable too
    def changefreq(self, obj):
        return "daily" if obj.comments_open() else "never"

from import BlogSitemap
sitemaps = {
    "blog": BlogSitemap
(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})

You can even generate sitemap indexes and it will pagenate the indexes on Google's limit of 50,000 urls so that you don't have a problem with it crawling your indexes.