Can base.html template contain dynamic content if used by direct_to_template

6 views
Skip to first unread message

Pete-Sitedesign

unread,
Jun 25, 2009, 1:23:21 PM6/25/09
to Django users
I want to build a site which has latest news on the side of all the
pages, I wanted to build the pages using simple templates (static
content) and then reference them using the direct_to_template in the
urls file.

Since each template extends base how can I get base to contain the
latest news or do I have to write a view for each template and pass
the news into them?

Sorry for the newbie question.

Alex Gaynor

unread,
Jun 25, 2009, 4:22:01 PM6/25/09
to django...@googlegroups.com
There are 2 ways to do this, either a) a template context process, which bsaically adds something to the context of all templates rendered, or b) an inclusion tag which basically let's you do an include but with a new context that you can create dynamically.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

Pete-Sitedesign

unread,
Jun 25, 2009, 4:27:06 PM6/25/09
to Django users
On Jun 25, 9:22 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Jun 25, 2009 at 12:23 PM, Pete-Sitedesign <
>
Thanks for that. I was have just been playing with the
context_processors way which is great since it provides the data to
all templates.
Could you explain the include idea a bit further please.
Do you mean {% include some_other_template.html %} then how do I
handle the URL to trigger a view to populate that included template
with the content?

PS Thanks for the reply.

regards Pete

Alex Gaynor

unread,
Jun 25, 2009, 4:29:27 PM6/25/09
to django...@googlegroups.com
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags are the docs on inclusion tags, they explain it better than I could :)

Pete-Sitedesign

unread,
Jun 25, 2009, 4:59:27 PM6/25/09
to Django users
OK Thanks for that. I have worked out that the context_processors
route is best for this one but the template_tags is ideal for another
part I was working on.

Thanks for the help.

Regards Pete

On Jun 25, 9:29 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Jun 25, 2009 at 3:27 PM, Pete-Sitedesign <
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#incl...
Reply all
Reply to author
Forward
0 new messages