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
Python get中修改的django会话不影响post中的会话_Python_Django_Session_Post_Get - Fatal编程技术网

Python get中修改的django会话不影响post中的会话

Python get中修改的django会话不影响post中的会话,python,django,session,post,get,Python,Django,Session,Post,Get,我在修改get请求中的request.session时遇到问题 假设GET请求中有以下代码: 用户可以从下拉菜单中的stings列表中进行选择,该列表与一个字典GroupId相关,该字典GroupId总结在一个键:值对中,该键是一个字符串 if request.method == "GET": if 'group' in request.GET: # Remeber the group in the session # Fi

我在修改get请求中的request.session时遇到问题

假设GET请求中有以下代码:

用户可以从下拉菜单中的stings列表中进行选择,该列表与一个字典GroupId相关,该字典GroupId总结在一个键:值对中,该键是一个字符串

    if request.method == "GET":
        if 'group' in request.GET:
            # Remeber the group in the session
            # First attempt
            request.session['grouporsection'] = request.GET['group']
            # Second attempt
            request.POST.get('grouporsection', request.GET['group'])
            # Print modified session
            print 'GET session:', request.session.items()
            # And return the date form
            content = { 'form' : DateTimeForm(initial={'beg' : '10/24/2015',
                                                       'end' : '10/24/2015'}) }
        else:
            # If group not in request return the date form 
            # and all groups to the group search form
            content = { 'form' : DateTimeForm(initial={'beg' : '10/24/2015',
                                                       'end' : '10/24/2015'}), 
                        'allgroups' : ['FS', 'PS', 'LS', 'JS', '...', '.:.', ':.:', 'blabla', 'and so on'] }
这将在运行testserver时在控制台中给出以下结果:

GET session: [(u'grouporsection', 'FS'),
              (u'end', u'10/24/2015'), 
              (u'beg', u'10/24/2015')]
当用户现在选择或不选择新日期并点击提交按钮时
request.method获取POST:

    elif request.method == 'POST':
        print 'POST session:', request.session.items()
在控制台中提供以下输出:

POST session: [(u'grouporsection', None),
               (u'end', u'10/24/2015'), 
               (u'beg', u'10/24/2015')]
如何在GET请求中修改request.session中的grouporsection,以便查看其是否已在POST请求中设置? 或者,为什么在用户从下拉列表中选择了一个组,然后在即将到来的日期时间表单中选择了beg或结束日期,并点击提交按钮后,grouporsections会消失

Thx提前,
BigZ

您的问题不是很清楚,最明显的结论是您正在修改此处未显示的代码的其他部分中的会话。虽然代码示例iteself有一些死代码,比如request.POST.get('grouporsection',request.get['group'])是的,我在代码的几个部分修改了会话,重用beg和end以及其他一些东西,比如在不同的视图中绘制了几个组的一些使用数据,这些数据汇总到各个部分。为了防止用户再次输入相同的内容,我将条目存储在request.session中,作为站点上显示的表单的初始值。我不确定这是我对请求会话的理解有问题,还是grouporsection变量在其他部分被覆盖了。我将查看my group.html并稍后编辑我的问题如果您的问题不太清楚,最明显的结论是您正在修改此处未显示的代码的其他部分中的会话。虽然代码示例iteself有一些死代码,比如request.POST.get('grouporsection',request.get['group'])是的,我在代码的几个部分修改了会话,重用beg和end以及其他一些东西,比如在不同的视图中绘制了几个组的一些使用数据,这些数据汇总到各个部分。为了防止用户再次输入相同的内容,我将条目存储在request.session中,作为站点上显示的表单的初始值。我不确定这是我对请求会话的理解有问题,还是grouporsection变量在其他部分被覆盖了。稍后我将查看我的group.html并编辑我的问题