Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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
使用会话变量在views.py中进行Django筛选_Django_Session Variables - Fatal编程技术网

使用会话变量在views.py中进行Django筛选

使用会话变量在views.py中进行Django筛选,django,session-variables,Django,Session Variables,我启动并运行会话,目前正在浏览器中设置变量“context_number”。在视图中,我想筛选这个变量。所以我在我的视图中有这个 def allcontexts(request): allcontexts = Context.objects.all() return render(request, 'context_manager/context_manager.html', { 'allcontexts':allcontexts, }) 为了过滤,我将

我启动并运行会话,目前正在浏览器中设置变量“context_number”。在视图中,我想筛选这个变量。所以我在我的视图中有这个

def allcontexts(request):
    allcontexts = Context.objects.all()
    return render(request, 'context_manager/context_manager.html',
    {
    'allcontexts':allcontexts,
    })
为了过滤,我将第二行更改为以下内容

    allcontexts = Context.objects.filter(context_number=____)
在空白中,我想插入CordExtNo.Co变量,因此CONTXEXNOD[dBALL] = CONTXEXLION[会话变量]


我似乎想不出正确的语法,有什么想法吗?

您可以使用语法访问会话变量:

allcontexts = Context.objects.filter(context_number=request.session.get("context_number"))