开发者

Multiple views loaded into a template

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


You can use Inclusion tags.


Use template context_processors


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜