python - How do I register custom filter in Google App Engine template system? -


according django documentation i've registered filter:

from google.appengine.ext.webapp import template # ... register = template.create_template_register() @register.filter(name='wld') def wld(result):     if result == 1 : return "win"     if result == 0 : return "loss"     if result == 0.5 : return "draw"     return "unknown" self.response.out.write(template.render("player.html", template_values)) 

somewhere in template have code:
{{result|wld}}

and when try render template, error: templatesyntaxerror: invalid filter: 'wld'

what doing wrong?

once have created custom tag library, need register django template engine:

from google.appengine.ext.webapp import template template.register_template_library('path.to.lib') 

note call template.register_template_library wrapper provided part of appengine sdk. once have put in main.py, new tags or filters should available in of templates without further work. no need use {% load %} tag.

an important note: functioning of register_template_library vary depending on version of django using in appengine application. if using 0.96, parameter path custom tags library file. if using django 1.2, python module path custom tag library. posted instructions making work in post on blog.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -