1👍
✅
You have to use the template loader module, and change your get_document
function:
from django.template.loader import render_to_string
def get_document(self, context):
data = render_to_string('documents\sample.txt', context)
return data.split("\n\n")
And you call it this way:
context['document'] = self.get_document(context)
Before that, you have to modify your settings.TEMPLATES
in order for the loader to find your file documents\sample.txt
.
Source:stackexchange.com