Search code examples
djangofooterdjango-urls

how to send a value from views.py to base.html everywhere on site?


I want to have a section with latest posts in my footer throughout my web site. My footer is located in base.html.

How can I have this:

def footer(request):
return render_to_response('base.html', {'posts_latest':Post.objects.order_by('-published'),},)

on every page? To have it shown I have to connect the function with an url, and I can't do that with all of them.

I tried this context processors tutorial, but I kept getting the error:

Error importing request processor module myapp.app.context_processors: "No module named context_processors" 

so I abandoned that idea.

What do you suggest?

Thanks in advance.


Solution

  • A custom context processor is what you are looking for, so you are already on the right track. You should try to solve your import problem. What django version are you running? Where is your processor located?