'How to extend multiple bases or conditional {% extends %} in one html page in django?
{% if request.user.profile.emp_desi in qa_list %}
{% extends "qa_base.html" %}
{% elif request.user.profile.emp_desi in mgr_list %}
{% extends "manager_base.html" %}
{% else %}
{% extends "common_base.html" %}
{% endif %}
How can I solve this problem?? based on designation I want to extend different different bases.
Solution 1:[1]
You can use include
You need to create a directory and template layout in such a way that you will have one base and multiple includes.
https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#include
{% if request.user.profile.emp_desi in qa_list %}
{% include "qa_base.html" %}
{% elif request.user.profile.emp_desi in mgr_list %}
{% include "manager_base.html" %}
{% else %}
{% include "common_base.html" %}
{% endif %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rahul.m |
