0

def 候选名单(请求):

my_shortlist = request.session['my_shortlist']

def shortlist_action(request, id, action):

id = int(id)
my_shortlist = request.session["my_shortlist"]
if action == "add":
    try:
        my_shortlist = request.session["my_shortlist"]
        if not id in my_shortlist:
            my_shortlist.append(id)
            request.session["my_shortlist"] = my_shortlist
        return HttpResponse("You're in try and you entered :  %s" % my_shortlist)
    except:
        my_shortlist = []
        my_shortlist.append(id)
        request.session["my_shortlist"] = my_shortlist
        return HttpResponse("You're in except and you entered :  %s" % my_shortlist)        
if action == "remove":
    my_shortlist = request.session["my_shortlist"]
    if id in my_shortlist:
        my_shortlist.remove(id)
    request.session["my_shortlist"] = my_shortlist
    return HttpResponse("You have removed all traces of: %s from %s" %(id, my_shortlist)) 
raise Http404

我有两个视图,我在视图中创建了一个会话变量,并尝试在另一个视图中访问该特定会话变量,但它给了我错误...任何建议都会对我有很大帮助...谢谢

4

0 回答 0