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 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.