Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » templates - pulling child templates [RSS Feed]

#1 Jan. 21, 2011 12:09:09

k.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


Hi all,

I am trying to display a parent django template (base.html) with a view
function called "base" like this:

def base(request):
return render_to_response('base.html')

The base.html gets displayed in the browser(firefox 3.x) but the child html
pages, holding content details, which extend base.html does not get pulled
automatically.
both base.html and child html are in the same dir.
I am using django 1.2.4 on ubuntu 10.10
what could be the problem?

pls let me know.
regards,
KM

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 21, 2011 12:31:55

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


On Fri, Jan 21, 2011 at 12:08 PM, km <srikrishnamo...@gmail.com> wrote:
> Hi all,
>
> I am trying to display a  parent django template (base.html) with a view
> function called "base" like this:
>
> def base(request):
>    return render_to_response('base.html')
>
> The base.html gets displayed in the browser(firefox 3.x) but the child html
> pages, holding content details, which extend base.html does not get pulled
> automatically.
> both base.html and child html are in the same dir.
> I am using django 1.2.4 on ubuntu 10.10
> what could be the problem?
>

Why would they get pulled in? How is django to know that? If you want
to render child.html, which extends base.html, then ask django to
render child.html.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 21, 2011 12:32:50

David D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


On 21/01/11 12:08, km wrote:
> Hi all,
>
> I am trying to display a parent django template (base.html) with a view
> function called "base" like this:
>
> def base(request):
> return render_to_response('base.html')
>
> The base.html gets displayed in the browser(firefox 3.x) but the child html
> pages, holding content details, which extend base.html does not get pulled
> automatically.

> pls let me know.

Um. It sounds like you've misunderstood something about how the template
inheritance mechanism works or what it's for. Do you expect rendering
base.html to show stuff in templates that extend base.html ??? It
doesn't work that way.

If you want to render a child template, render the child template.

Say you have a base template, base.html, with two blocks foo and bar.
If your child.html template extends base.html, and provides a block foo,
when you render child.html, it renders like the base template but with
the foo specified in the child.html.

(OTOH, if you want to include a template in another template, you can
use the include tag)


** base.html:

{% block foo %}
Hello
{% endblock foo %}
{% block bar %}
World
{% endblock bar %}

** render base.html:

Hello
World

** child.html:

{% extends "base.html" %}
{% block foo %}
Goodbye
{% endblock foo %}

** render child.html:

Goodbye
World



--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 21, 2011 12:33:54

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


On Friday, January 21, 2011 12:08:57 PM UTC, km wrote:
>
> Hi all,
>
> I am trying to display a parent django template (base.html) with a view
> function called "base" like this:
>
> def base(request):
> return render_to_response('base.html')
>
> The base.html gets displayed in the browser(firefox 3.x) but the child html
> pages, holding content details, which extend base.html does not get pulled
> automatically.
> both base.html and child html are in the same dir.
> I am using django 1.2.4 on ubuntu 10.10
> what could be the problem?
>
> pls let me know.
> regards,
> KM
>

You're doing it the wrong way round. Child templates extend parent
templates, so you need to render the child.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 21, 2011 14:45:01

k.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


Hi all,

On Fri, Jan 21, 2011 at 6:03 PM, Daniel Roseman <dan...@roseman.org.uk>wrote:

> On Friday, January 21, 2011 12:08:57 PM UTC, km wrote:
>>
>> Hi all,
>>
>> I am trying to display a parent django template (base.html) with a view
>> function called "base" like this:
>>
>> def base(request):
>> return render_to_response('base.html')
>>
>> The base.html gets displayed in the browser(firefox 3.x) but the child
>> html pages, holding content details, which extend base.html does not get
>> pulled automatically.
>> both base.html and child html are in the same dir.
>> I am using django 1.2.4 on ubuntu 10.10
>> what could be the problem?
>>
>> pls let me know.
>> regards,
>> KM
>>
>
> You're doing it the wrong way round. Child templates extend parent
> templates, so you need to render the child.
>
Many thanks for the clarification. that makes it clear.
regards,
KM


> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Jan. 21, 2011 14:59:07

k.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


Hi all,

The docs say we can have multiple child templates extending the parent
template. But then how to render multiple child templates in one call ?

regards,
KM

On Fri, Jan 21, 2011 at 8:14 PM, km <srikrishnamo...@gmail.com> wrote:

>
> Hi all,
>
> On Fri, Jan 21, 2011 at 6:03 PM, Daniel Roseman <dan...@roseman.org.uk>wrote:
>
>> On Friday, January 21, 2011 12:08:57 PM UTC, km wrote:
>>>
>>> Hi all,
>>>
>>> I am trying to display a parent django template (base.html) with a view
>>> function called "base" like this:
>>>
>>> def base(request):
>>> return render_to_response('base.html')
>>>
>>> The base.html gets displayed in the browser(firefox 3.x) but the child
>>> html pages, holding content details, which extend base.html does not get
>>> pulled automatically.
>>> both base.html and child html are in the same dir.
>>> I am using django 1.2.4 on ubuntu 10.10
>>> what could be the problem?
>>>
>>> pls let me know.
>>> regards,
>>> KM
>>>
>>
>> You're doing it the wrong way round. Child templates extend parent
>> templates, so you need to render the child.
>>
> Many thanks for the clarification. that makes it clear.
> regards,
> KM
>
>
>> --
>> DR.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Jan. 21, 2011 15:34:57

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templates - pulling child templates


On Fri, Jan 21, 2011 at 2:59 PM, km <srikrishnamo...@gmail.com> wrote:
> Hi all,
>
> The docs say we can have multiple child templates extending the parent
> template. But then how to render multiple  child templates in one call ?
>
> regards,
> KM
>

I don't think the docs say that. Each call to render a template takes
the name of a single template, which can extend a single template,
which in turn can extend another template.

Template extension allows you to build one big template by reading in
the child template and inserting the named blocks into the
corresponding blocks in the parent template, producing one large
template. You can't render multiple templates at once.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 14th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support