Last active
December 19, 2015 08:09
-
-
Save mbylstra/5924205 to your computer and use it in GitHub Desktop.
using Django templates for fancy string interpolation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Template("The first stooge in the list is {{ stooges.0 }}.") | |
c = Context({"stooges": ["Larry", "Curly", "Moe"]}) | |
t.render(c) | |
#or if you want to render from an existing html template | |
from django.template.loader import render_to_string | |
rendered = render_to_string('my_template.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment