3👍
✅
There are two methods:
-
Use
from_string()
: https://docs.djangoproject.com/en/2.1/ref/templates/api/#django.template.Engine.from_string -
Use Template object directly.
Example.
from django.template import Template
template = Template("My name is {{ my_name }}.")
2👍
You can use django’s template.Template Class
from django import template
html_template_str = "<html> Hello {{ Name }} </html>"
t = template.Template(html_template_str)
c = template.Context({'Name':"Name"})
html = t.render(c)
html will contain rendered template html
Source:stackexchange.com