Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django:无法呈现请求上下文_Django_Requestcontext - Fatal编程技术网

Django:无法呈现请求上下文

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 }}

我的视图中有以下内容。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 }}
但是当我加载主页时,上面的请求上下文中没有任何内容被呈现

编辑1:


看来我走错了路。我的目标是在一个固定的边栏中显示整个网站中“公告”类别下的帖子。无论打开哪个页面,该页面的侧边栏都应该只包含“公告”类别的帖子。对如何实现它有什么建议吗?

创建一个工具条,并在您想要显示该工具条的模板中使用它

您确定有与该类别匹配的博客项目吗?如果我没有记错,您可以使用HttpResponse.content将格式化页面视为字符串。我在粘贴检查中发现了一些有用的东西,为了确保您的博客查询返回数据,django调试工具栏将允许您查看所有上下文值