[Fixed]-Reuse template for HTML layout object

1👍

You can access the unmodified template string at Template.source:

template = loader.get_template('my-template.html')
HTML(template.source)

However I think it will be more efficient (and less magical) just to do:

HTML('{% include "my-template.html" %}')

0👍

You can use render_to_string():

from django.template.loader import render_to_string

html = render_to_string('your-template.html', {})
HTML(html)

Leave a comment