Recently I was in need to have a code that could enable the extending of base file in other template files depending on type of user logged in into the site. This basically is used when we want different different look of site for different types of users. Following are the methods which I used before I finally got the right solution :
First I used the code something like this in my template file :
{% if user.is_superuser %}
{% extends "base.html" %}
{% else if user.is_active %}
{% extends "base_client.html" %}
{% else %}
{% extends "base_noclient.html" %}
But this code gave error. It then did not set the correct blocks in the templates.
Then I thought to use include instead of extend, like :
{% if user.is_superuser %}
{% include "base.html" %}
{% else if user.is_active %}
{% include "base_client.html" %}
{% else %}
{% include "base_noclient.html" %}
This code managed to have different looks for different users but through this all the site got de-structured.
Then finally with the help of Internet and Django mailing list I got the solution which goes as follows :
In the templates, use this code..
{% extends base_template|default:"base.html" %}
EMPLATE_CONTEXT_PROCESSORS = (