1👍
✅
Just use engines.from_string(template_code)
from django.template import engines
document = DocumentService.objects.get(pk=1)
data = {'data': document.html_content}
str_template = render_to_string("document.html", data)
response = PDFTemplateResponse(
request=request,
template= engines['django'].from_string(str_template),
filename=filename,
context=data,
show_content_in_browser=True,
cmd_options=cmd_options,
)
and inside your document.html you’ve to add like this
<body>
{{data|safe}} <!--- Use safe if you want to render html --->
</body>
Source:stackexchange.com