Django(其二)
阿新 • • 發佈:2018-11-17
session
def session_login(request): if request.method=='POST': username = request.POST.get('user') password = request.POST.get('pwd') user = UserInfo.objects.filter(name=username,pwd=password).first() if user: request.session['is_login']=True request.session['username']=user.name return HttpResponse('登入成功!') else: return redirect('/cookie/') return render(request,"cookie.html") def session_index(request): session_name = request.session['is_login'] if session_name: username = request.session['username'] return render(request,"c_index.html",{'username':username}) return render(request,'c_index.html')