Skip to content

Instantly share code, notes, and snippets.

@mbylstra
Last active December 19, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbylstra/5924205 to your computer and use it in GitHub Desktop.
Save mbylstra/5924205 to your computer and use it in GitHub Desktop.
using Django templates for fancy string interpolation
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