0

デフォルト候補リスト (リクエスト):

my_shortlist = request.session['my_shortlist']

def shortlist_action(リクエスト、ID、アクション):

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