Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. >>> from django.template import Context, Template
  2. >>> t = Template("My name is {{ person.first_name }}.")
  3. >>> d = {"person": {"first_name": "Joe", "last_name": "Johnson"}}
  4. >>> t.render(Context(d))
  5. "My name is Joe."
  6.  
  7. >>> class PersonClass: pass
  8. >>> p = PersonClass()
  9. >>> p.first_name = "Ron"
  10. >>> p.last_name = "Nasty"
  11. >>> t.render(Context({"person": p}))
  12. "My name is Ron."
  13.  
  14. >>> class PersonClass2:
  15. ... def first_name(self):
  16. ... return "Samantha"
  17. >>> p = PersonClass2()
  18. >>> t.render(Context({"person": p}))
  19. "My name is Samantha."
  20.  
  21. >>> t = Template("The first stooge in the list is {{ stooges.0 }}.")
  22. >>> c = Context({"stooges": ["Larry", "Curly", "Moe"]})
  23. >>> t.render(c)
  24. "The first stooge in the list is Larry."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement