Call a Django renderer in memory without any files from strings?

I created a macro language for my users based on the Django template language. Users enter their templates / macros into UITextFields, which can be displayed in the context of larger documents. Therefore, I have large multi-line string snippets of django template code that should be filled with variables that are also stored in memory. I don’t want to ever dump anything into files, I need to display these templates

How can I call a Django visualizer for a template that is stored in a string in memory (in python instance variables)? The variables that should populate this template are also instance variables stored in memory.

+3
source share
1 answer
from django.template import Context, Template

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

Source: https://habr.com/ru/post/1750844/


All Articles