Advertisement
danfalck

tornado_template_syntax.py

Nov 17th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. from tornado.template import Template
  2.  
  3. #simple generation
  4. print Template("{{ 3*3 }}").generate()
  5.  
  6. #generate using function
  7. def add(x,y):
  8.     return x + y
  9.  
  10. print Template("{{a(1,2)}}").generate(a = add)
  11.  
  12.  
  13. #generate with two functions
  14. def sub(x,y):
  15.     return x-y
  16.  
  17. print Template("{{a(1,2)}} , {{b(4,3)}}").generate(a = add,b = sub)
  18.  
  19. #substitution within the Template statement
  20. text = "{{a(1,2)}} , {{b(4,3)}}"
  21.  
  22. print Template(text).generate(a = add,b = sub)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement