Django - define template includes/extends in one place in the same way url paths are defined in urls.py? -


i'm enjoying transition php python/django , ability extend templates. however, i'm still finding i'm still doing fair bit of repetitive work in defining templates , extending other templates, etc. wondering if knows of way abstract out 1 file tells templates other templates should extend/include?

the simple answer is, not default functionality. abstracting things {% base %} tag file make templates harder read.

one way remove "extra work" make editor you. in case, define of templates .dhtml files , have vim paste in template file whenever open empty .dhtml file. programming-centric editors have functionality built in prevent having manually copy/paste or retype basic structures.

another thing consider may building templates in less-than-optimal way. example, if have different base templates, replace different base templates css? css can change templates in ways programmers can overlook. example, check out css zen garden. changes see amazing, , not change base html @ all.

for change this, have in templates/base.html:

<link rel="stylesheet" type="text/css" href="{{ media_url }}css/default.css" /> {% block extracss %}{% endblock %} 

and in order include over-riding css, place in templates:

{% extends "base.html" %} {% block extracss %}     <link rel="stylesheet" type="text/css" href="{{ media_url }}css/orchid_beauty.css" /> {% endblock %} 

Comments