O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

28.3.1 Post Sitemap

We therefore need a Sitemap subclass. We can start with our blog app, creating a sitemaps.py file where we import our tools, as shown in Example 28.22.

Example 28.22: Project Code

blog/sitemaps.py in b1f09978d6

1   from datetime import date 2 3   from django.contrib.sitemaps import Sitemap 4 5   from .models import Post

We then declare our subclass in Example 28.23. The goal is to provide a list of all of the pages in our blog app. Because we’ve implemented get_absolute_url() on Post, this turns out to be surprisingly easy: we just need to return a list of Post objects in the items() method. We can also tell the search engine when the Post instance was modified thanks to the lastmod() method. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required