27.3.4 Listing the Latest Blog Posts

When we want to build a more complicated template tag, Django cannot provide a decorator to make our life easier. Instead, we must deal with the objects that Django uses internally.

For a template tag, Django expects the creation of a function and a subclass of the Node class. The function we create can be thought of loosely as a function to lex and parse the call to the template tag. The Node subclass is what Django uses in the abstract syntax list (yes, that’s right—it is not a tree but a list).

From within a node, we can do most of anything available to Python within the confines of a template. One of the more powerful features is the ability to add data to the template. In this section, we create a custom ...

Get Django Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.