I have a string that looks like
string '''
<html>
<head>
{% block head %}{% endblock %}
... other stuff ...
</head>
<body>
{% block body %}{% endblock %}
... other stuff ...
</body>
</html>
'''
I would like the following django template to inherit from the above string:
{% block head %}
... other stuff ...
{% endblock %}
{% block body %}
<h1>Other stuff</h1>
{% endblock %}
Since the string is not in a file a can’t just specify it’s filename to the template rendering engine. Any ideas?
It turns out there’s an even simpler way to achieve this:
Where the index.html file looks like this:
In this case, the template object (as opposed to just a string) is passed into the context of the child template and used as the variable in the ‘extends’ tag.