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:
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
Post a Comment