Sunday, July 29, 2018

Documentation on Template Inheritance

The Template Inheritance documentation could use some more guidelines.


First,

It's not indicated in the Django Documentation that the child template is the actual view to be loaded, contrary to what its name would imply :

Template inheritance allows you to build a base "skeleton" template that contains all the common elements of your site and defines blocks that child templates can override.

The only indication of this mechanism lies in the implication that the system won't access ("evaluate") the parent template first, but only after it evaluates the child template :

When the template system evaluates this template, first it locates the parent – in this case, "base.html".

I had to read a Stackoverflow question/answer to get this : django template extends not working.


Second,

The base template is not located by default in the same folder as the child template, as explained in the Stackoverflow question/answer : extend base.html problem.

It can be argued that while the view's render refers to myapp\child_template.html, it's only normal that the extends should refer to "myapp\base_template.html" to find it in the same directory. Except the documentation makes no mention of it and simply tells to extend "base_template.html", although in the Base tutorial, for example, it tells to put templates in "mysite\myapp\templates\templates\".

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8d77c7d5-1472-4b75-8d65-4fcc1d6bd486%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment