Dowemo


def login(request):


 if request.method == 'GET':


 return render(request, 'login.html', {})


 if request.method == 'POST':


 username = request.POST['username']


 password = request.POST['pwd']


 count = UserInfo.objects.filter(username=username).count()


 if count == 0:


 return redirect(to='login')


 else:


 user = UserInfo.objects.get(username=username)


 if user.password == password:


 response = redirect(to='index') #返回一个response对象


 response.set_cookie('uname', username, 3600)#设置一个cookie,键为uname


 return response


 else:


 return redirect(to='login')














def index(request):


 context={}


 context['uname']=request.COOKIES.get('uname')


 return render(request, 'index.html', context)















Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs