Django:无法呈现请求上下文
我的视图中有以下内容。py:Django:无法呈现请求上下文,django,requestcontext,Django,Requestcontext,我的视图中有以下内容。py: def announcements(request): return render_to_response('events.html', { 'posts1': Blog.objects.filter(category__title="Announcements") }, context_instance=RequestContext(request) ) 在my base.html中: {{ posts1 }}
def announcements(request):
return render_to_response('events.html', {
'posts1': Blog.objects.filter(category__title="Announcements")
}, context_instance=RequestContext(request)
)
在my base.html中:
{{ posts1 }}
但是当我加载主页时,上面的请求上下文中没有任何内容被呈现
编辑1:
看来我走错了路。我的目标是在一个固定的边栏中显示整个网站中“公告”类别下的帖子。无论打开哪个页面,该页面的侧边栏都应该只包含“公告”类别的帖子。对如何实现它有什么建议吗?创建一个工具条,并在您想要显示该工具条的模板中使用它 您确定有与该类别匹配的博客项目吗?如果我没有记错,您可以使用HttpResponse.content将格式化页面视为字符串。我在粘贴检查中发现了一些有用的东西,为了确保您的博客查询返回数据,django调试工具栏将允许您查看所有上下文值