To create our own custom template tags we have to define a Node subclass which implements a render method.
import datetime
from django import template
class CurrentTimeNode(template.Node):
def __init__(self, format_string):
self.format_string = format_string
def render(self, context):
return datetime.datetime.now().strftime(self.format_string)
It seems the context parameter for the render function is a 'context object' and not a 'request context object'. Indeed this section of the same article seems to support this - To create our own custom template tags we have to define a Node subclass which implements a render method.
Anyway when I followed the example and printed the context object it looks to be a request object. Is this a bug? I'm using the latest django.