passing context data to inherited templates

12 views
Skip to first unread message

Mike

unread,
Jan 29, 2012, 12:34:50 AM1/29/12
to django...@googlegroups.com
In a project I'm working on I have a status bar at the top of the webpage that will render data using template tags.  The status bar will be displayed on all of my views, so I want to put the html code in my base template.  The base template is imported to all of templates using the 'extends' template tag.  Now the base template needs a dictionary of data. My question is, how do I pass this data to the base template?  I'm passing it in the context data of every view that renders a template, but it seems like there should be a better way - for example the base template calling out to a python function that can add data to the context before its rendered. Is there any other way to pass data to a base template?


Daniel Roseman

unread,
Jan 29, 2012, 12:05:41 PM1/29/12
to django...@googlegroups.com
On Sunday, 29 January 2012 05:34:50 UTC, Mike wrote:
In a project I'm working on I have a status bar at the top of the webpage that will render data using template tags.  The status bar will be displayed on all of my views, so I want to put the html code in my base template.  The base template is imported to all of templates using the 'extends' template tag.  Now the base template needs a dictionary of data. My question is, how do I pass this data to the base template?  I'm passing it in the context data of every view that renders a template, but it seems like there should be a better way - for example the base template calling out to a python function that can add data to the context before its rendered. Is there any other way to pass data to a base template?


This is exactly what context processors are for:
--
DR. 
Reply all
Reply to author
Forward
0 new messages