I am writing some functions to do things like format dates and text in my templates.
def coolfunc(s): return s + ' is cool' app.jinja_env.globals.update(coolfunc=coolfunc) app.jinja_env.filters['coolfunc'] = coolfunc
template:
{{ coolfunc(member.name) }} {{ member.name | coolfunc }}
exit:
John is cool John is cool
I am not sure what the real difference between functions and filters is. It seems to me that the filters just look cleaner?
python flask jinja2
Patrick yan
source share