django - How to extend a base.html using two different files? -



django - How to extend a base.html using two different files? -

i'm writing application in user can take 1 of several tools info analysis , open in panel on main page. possible utilize django "extends" , have each tool defined in different file?

the minimal illustration of im strugling this:

base.html

<div> {% block left_panel %} left block {% endblock content%} </div> <div> {% block right_panel %} right block {% endblock %} </div>

and sample left_panel , right_panel tools:

left1.html

{% extends "base.html" %} {% block left_panel %} <p>test left 1</p> {% endblock %}

right1.html

{% extends "base.html" %} {% block right_panel %} <p>test right 1</p> {% endblock %}

is there way render base.html both blocks overwriten?

i believe best way implement requirement create new template extends base.html , includes left1.html , right1.html. this:

{% extends "base.html" %} {% block left_panel %} {% include "left1.html" %} {% endblock content%} {% block right_panel %} {% include "right1.html" %} {% endblock %}

update based on op's comment: need 1 configurable template, not 100. let's based on tools user selects, view passes left_tool , right_tool context variables template. now, can this:

{% block left_panel %} {% if left_tool == "tool1" %} {% include "left1.html" %} {% elif left_tool == "tool2" %}} {% include "left2.html" %} etc ... {% else %} {% include "left10.html" %} {% endif %} {% endblock content%}

you'll same right panel. of course of study above little naive , not dry -- instead instance generate name of template included in view , pass straight template, or utilize custom node etc.

django django-templates

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -