views:

18

answers:

1

I have built a Macro language for my users that is based upon the Django template language. Users enter into UITextFields their template/macro snippets that can be rendered in the context of larger documents. So I have large multi-line string snippets of django template code that should be populated with variables that are also stored in memory. I don't want to ever have to dump anything to files, I need to render these template

How can I invoke the Django template renderer on a template that is stored in a string in memory (in python instance variables)? The variables that should populate that template are also instance variables stored in memory.

+2  A: 
from django.template import Context, Template

template = Template("this is a template string! {{ foo }}")
c = Context({"foo": "barbarbar"})
print template.render(c)
Mathiasdm