Skip to content Skip to sidebar Skip to footer

How To Make Django Template Engine To Render In Memory Templates?

I am storing my templates in the database and I don't have any path to provide for the template.render method. Is there any exposed method which accepts the template as a string? I

Solution 1:

Based on the the docs for using the template system:

from django.template import Template, Context

t = Template("My name is {{ my_name }}.")
c = Context({"my_name": "Adrian"})
t.render(c)

Solution 2:

Instantiate Template with the string to use as a template.


Solution 3:

In Django < 1.8:

from django.template.loader import get_template_from_string

tpl = Template(get_template_from_string("My name is {{ my_name }}."))

Post a Comment for "How To Make Django Template Engine To Render In Memory Templates?"