It was suggested on #pocoo irc that I decorate timestampformat with @app.template_filter(), but that assumes I'm using jinja with Flask. Using jinja2 as a stand-alone template engine, I'm getting an error using a custom filter in a derived class: http://dpaste.com/244972/
I've also tried using the @environmentfilter decorator on timestampformat with no success. Any further suggestions? Jeff Bauer Rubicon, Inc. On Sep 17, 8:03 am, Jeff Bauer <[email protected]> wrote: > 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.
