I got a problem where I want to use template including in Django.
Here is the real example:
I got 3 files:
- home.html (will get the context variable passed from Views)
- base.html (the skeleton template file)
- and the header.html (included by base.html).
If I put the code below directly in base.html without including header.html, the {{title}} variable passed from home is correctly called. But if I include the header.html in base.html, the {{title}} variable’s value cannot be called.
<title>{% block title %}{% endblock %} | {{ SITE_INFO_TITLE }}</title>
Is there any solution to this problem? Thanks.
As far as I know blocks and variable are distinct in django.
If you want to pass title as a context variable you have to set it using a declaration in base.html such as :
Which in turn contains :
You can also set it in home like this.
{% block title %} Home page {%endblock%}
But I also try to set in the template context.
Without the title block.
I think you can also see the
withtemplate tag I think it is possible to set a context variable using this tag.