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?
Is there any workaround?
A Django project can be configured with one or several template engines (or even zero if you don't use templates). Django ships built-in backends for its own template system, creatively called the Django template language (DTL), and for the popular alternative Jinja2.
Being a web framework, Django needs a convenient way to generate HTML dynamically. The most common approach relies on templates. A template contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
Django Template Language (DTL) is the primary way to generate output from a Django application. You can include DTL tags inside any HTML webpage. The basic DTL tag you can include in an HTML webpage is: 1. {% Tag %}
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)
Instantiate Template
with the string to use as a template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With