python - How to chain {% includes %} in django templating -
i have base.html
file looks this:
<!doctype html public "-//w3c//dtd html 4.01//en"> <html lang="en"> <head> {% block header %}{% endblock %} </head> <body> {% block content %}{% endblock %} {% block footer %}{% endblock %} </body> </html>
and have file, auth.html
extends this:
{% extends "base.html" %} {% block content %} [my content] {% endblock %}
which works fine, want have separate header.html
file plugs header
block above.
what's right way construction auth.html
, header.html
in order include both , have both extend base.html
?
i tried adding {% include header.html %}
line auth.html
, , structuring header.html
follows:
{% extends "base.html" %} {% block header %} [header content here] {% endblock %}
but didn't work. how should doing this?
you need {{ block.super }}
:
if need content of block parent template, {{ block.super }} variable trick. useful if want add together contents of parent block instead of overriding it.
its burried in template inheritance documentation.
suppose want add together stuff header
block in auth.html
. header
defined in index.html
:
your auth.html
like:
{% extends "index.html" %} {% block header %} {{ block.super }} stuff, come after whatever in header block {% endblock %}
python html django
No comments:
Post a Comment