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.
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. ...
Get Django Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.