What is the use of parent_template filter in Django templates

40 views
Skip to first unread message

Prateek

unread,
Nov 1, 2016, 2:40:39 PM11/1/16
to Django users
I am reading Django Unleashed in which the author uses the following code to extends the template

{% extends parent_template|default:"organizer/base_organizer.html" %}

What does parent_template do ?

I am unable to find this tag in the Django Documentation

ludovic coues

unread,
Nov 1, 2016, 2:46:57 PM11/1/16
to django...@googlegroups.com
Is there any variable called parent_template in the context ?
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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/41a3aaf7-4994-4fc1-9ec2-eff3e8eebd91%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Andrew Pinkham

unread,
Nov 16, 2016, 9:32:15 PM11/16/16
to django...@googlegroups.com
On Nov 1, 2016, at 10:26 AM, Prateek <pratee...@gmail.com> wrote:
> I am reading Django Unleashed in which the author uses the following code to extends the template
>
> {% extends parent_template|default:"organizer/base_organizer.html" %}
>
> What does parent_template do ?

Hi Prateek,
Thanks for buying my book!

The first time we use parent_template---a variable, not a template tag---is on page 108 of the book. The paragraph before Example 4.53 provides a full explanation of why I opt to use a variable with a default, rather than a magic (read: hardcoded) string.

Hope that's helpful!

Andrew

Reply all
Reply to author
Forward
0 new messages