views:

64

answers:

4

Hay guys, in PHP when i want to load a differnet page (render, with all variables outputting) i would use

include 'mypage.php'

This would load the page up and render the output.

How do i do something like this in Django? My problem is that i have a "quick list" which lists a bunch of popular items. I want this list to appear on every page, even if i don't call the object.

any ideas?

EDIT: The view is called shop.app.popular_items

+2  A: 

Use template context_processors

Lakshman Prasad
Context processor only gives you the variables. You'll still need to handle the presentation somewhere, so you'll end up having the processor putting the values in the context automagically, but you'll have to put the right template code in all your templates, or include it. That's why I like Inclusion tags better ("Explicit is better than implicit").
Ofri Raviv
+2  A: 

You can use Inclusion tags.

Ofri Raviv
+2  A: 

Edit:

After Daniel's answer and as you said you want to have it on every page,
becomingGuru's answer is probably the best solution.


This does not belong into the view (if you not want to display this as a standalone page).

This should go into a custom template tag.

Felix Kling
+1  A: 

To answer your question to becomingGuru on when to use context processors and when to use inclusion tags, remember that context processors are run on every template render. So they should only be used when you know you will always need the value.

Daniel Roseman