I'm having a problem with applying a template filter in a derived
class:

# jtest.py
import datetime
from jinja2 import Environment, PackageLoader

def timestampformat(value, format="%a %b %d %Y %H:%M:%S"):
    return value.strftime(format)

class BaseReport(object):
    def __init__(self, template_file):
        env = Environment(loader=PackageLoader('jtest', 'templates'))
        self.template = env.get_template(template_file)
        env.filters['timestampformat'] = timestampformat

class DetailReport(BaseReport):
    def __init__(self, **kw):
        super(DetailReport, self).__init__('jtest.html')

if __name__ == '__main__':
    report = DetailReport()
    print report.template.render(now=datetime.datetime.now())
....
Given the contents of jtest.html:

  jtest: {{ now | timestampformat }}

The above code produces:

  File "/home/jbauer/jtest/templates/jtest.html", line 1, in template
    jtest: {{ now | timestampformat }}
jinja2.exceptions.TemplateAssertionError: no filter named
'timestampformat'

How do I make the timestampformat filter work in DetailReport?

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to