44👍
✅
SOLVED! the way to do this –
from django.template.loader import render_to_string
rendered = render_to_string('my_template.html', { 'foo': 'bar' })
thanks to ned for pointing to the Django docs
22👍
Adapted from the Django docs:
from django.template import Context, Template
t = Template("My name is {{ my_name }}.")
c = Context({"my_name": "Adrian"})
output = t.render(c)
- [Django]-Override existing Django Template Tags
- [Django]-Including a querystring in a django.core.urlresolvers reverse() call
- [Django]-Check permission inside a template in Django
0👍
There is even a simpler way (if you need to extract html data from render method):
R = render('template.html', context)
data = str(R.content)
- [Django]-How can I disable Django's csrf protection only in certain cases?
- [Django]-What is @permalink and get_absolute_url in Django?
- [Django]-ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory:
Source:stackexchange.com