views:

17

answers:

1

Hi, It is a question about django that has found absolutely no answer for me. Let's suppose I have a site where I display two blocks in the sidebar :

  1. A list of the last users who've logged in
  2. A list of the last published blog articles

Let's say that these blocks are to be displayed on 80% of the website urls and presented using template files. The data for these blocks is generated by code (obviously), bt not by url views.

Well, how to do such a thing ?

A: 

You might want to take a look at custom template tags.

Edit: more specifically, look at inclusion template tags.

André Caron
Hi André, I think I would not use them for this purpose. I have found the source code of a small site given for example, and it uses context preprocessors so that it can layout the contents of the context data the way I want.
lovelive
But! Template context processors are too much overhead I think and there is maybe something lighter.
lovelive
It seems to me, however, that it's the ideal solution. You just stick the tag in your template, and that tag can fetch your navigation bar. This is one of the uses described in the help at http://docs.djangoproject.com/en/dev/howto/custom-template-tags/.
André Caron
Hey André, you dit it ! The inclusion tags are exactly what I was looking for actually, generating context data and include it in a template, which is in turn included in another template. So yes, it is the ideal solution, I did not see this while reading the docs.
lovelive
Cool! I see you're new to StackOverflow. Don't forget to accept answers when they solve your problem!
André Caron
Yep, I'm new. And I've ticked your answer :)
lovelive
It's important that you do. If you have many question with no answers, other users will see your low accept rate and won't spend time to answer your new questions!
André Caron

related questions