[Django]-How to make Django template engine to render in memory templates?

20👍

Instantiate Template with the string to use as a template.

82👍

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)

5👍

In Django < 1.8:

from django.template.loader import get_template_from_string

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

Leave a comment