开发者

Django: Failure to render Request Context

开发者 https://www.devze.com 2023-03-29 02:09 出处:网络
I have this in my views.py: def announcements(request): return render_to_response(\'events.html\', { \'posts1\': Blog.objects.filter(category__title=\"Announcements\")

I have this in my views.py:

def announcements(request):
    return render_to_response('events.html', {
        'posts1': Blog.objects.filter(category__title="Announcements")
         }, context_instance=RequestContext(request)
    )

And this in my base.html:

{{ posts1 }}

But nothing from the above request context gets rendered when I load the home page.

Edit 1:

It looks like I am on a wrong path here. My aim is to display the posts under "announcement" category throughout my开发者_运维百科 website in a fixed sidebar. Whichever page is opened the sidebar in that page should contain only posts from "announcement" category. Any suggestion for how to achieve it?


Create an inclusion template tag and use it in templates where you want to display that sidebar.

0

精彩评论

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