Re: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread robinne
Ok, thanks everyone for the replies. I will take a look at these
suggestions.

On May 13, 6:06 am, Michal Petrucha  wrote:
> On Thu, May 12, 2011 at 08:15:59PM -0700, robinne wrote:
> > How can I render dynamic content in a base template if I only call a
> > view on my child template?
>
> > What I am trying to do is setup a base template that will include
> > "Profile" information for the user who is logged in, for example:
> > "Welcome John", instead of "login here", on every page. But if I call
> > my child page "/Home" (for example) and it extends "base.html", how do
> > I render the dynamic content within base.html? Thanks.
>
> You can use either custom template tags as suggested by others. The
> alternative is to create custom context processors that will add
> dynamic data you want to display into the context. Then you can use it
> even in your base template. However, you'll have to make sure each
> view uses a RequestContext when rendering templates in order for the
> context processors to be applied.
>
> As for the specific problem you're solving, RequestContext already
> contains user data which means you don't need anything extra. Just
> check in your base template if a user is logged in and show his
> username if yes or a login link otherwise.
>
> Michal
>
>  signature.asc
> < 1KViewDownload

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread Michal Petrucha
On Thu, May 12, 2011 at 08:15:59PM -0700, robinne wrote:
> How can I render dynamic content in a base template if I only call a
> view on my child template?
> 
> What I am trying to do is setup a base template that will include
> "Profile" information for the user who is logged in, for example:
> "Welcome John", instead of "login here", on every page. But if I call
> my child page "/Home" (for example) and it extends "base.html", how do
> I render the dynamic content within base.html? Thanks.

You can use either custom template tags as suggested by others. The
alternative is to create custom context processors that will add
dynamic data you want to display into the context. Then you can use it
even in your base template. However, you'll have to make sure each
view uses a RequestContext when rendering templates in order for the
context processors to be applied.

As for the specific problem you're solving, RequestContext already
contains user data which means you don't need anything extra. Just
check in your base template if a user is logged in and show his
username if yes or a login link otherwise.

Michal


signature.asc
Description: Digital signature


Re: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread Gabe
I suggest reading about inclusion tags:
http://docs.djangoproject.com/en/1.3/howto/custom-template-tags/

worked for me

Gabe

On 13 Maj, 07:51, Mateusz Marzantowicz 
wrote:
> On Fri, May 13, 2011 at 5:15 AM, robinne wrote:
>
> How can I render dynamic content in a base template if I only call a> view on 
> my child template?
>
> > What I am trying to do is setup a base template that will include
> > "Profile" information for the user who is logged in, for example:
> > "Welcome John", instead of "login here", on every page. But if I call
> > my child page "/Home" (for example) and it extends "base.html", how do
> > I render the dynamic content within base.html? Thanks.
>
> I think you should consider using template tags mechanism. Either it is
> already built into your auth/login application (there are some tags
> included) or you might write your own custom tags. Please refer to
> documentation 
> at:http://docs.djangoproject.com/en/1.3/howto/custom-template-tags/.

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread Mateusz Marzantowicz
On Fri, May 13, 2011 at 5:15 AM, robinne wrote:

How can I render dynamic content in a base template if I only call a
> view on my child template?
>
> What I am trying to do is setup a base template that will include
> "Profile" information for the user who is logged in, for example:
> "Welcome John", instead of "login here", on every page. But if I call
> my child page "/Home" (for example) and it extends "base.html", how do
> I render the dynamic content within base.html? Thanks.
>
>
I think you should consider using template tags mechanism. Either it is
already built into your auth/login application (there are some tags
included) or you might write your own custom tags. Please refer to
documentation at:
http://docs.djangoproject.com/en/1.3/howto/custom-template-tags/ .

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Template inheritance, how to render dynamic content in base templates

2011-05-13 Thread Daniel Roseman
On Friday, May 13, 2011 4:15:59 AM UTC+1, robinne wrote:
>
> How can I render dynamic content in a base template if I only call a 
> view on my child template? 
>
> What I am trying to do is setup a base template that will include 
> "Profile" information for the user who is logged in, for example: 
> "Welcome John", instead of "login here", on every page. But if I call 
> my child page "/Home" (for example) and it extends "base.html", how do 
> I render the dynamic content within base.html? Thanks.


The base template is rendered along with the child template, as long as the 
child uses the {% extends %} tag.
--
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 at 
http://groups.google.com/group/django-users?hl=en.