def main(req):
username = req.session.get('username',None)
try :
print req.session['username']
print req.session.session_key
print '----------------'
except:
try:
req.session['username']
return render_to_response('main.html')
except:
try:
a=req.POST['username']
if (check_user(req.POST['username'],req.POST['password'])== 1):
req.session['username']=req.POST['username']
print req.encoding
return render_to_response('main.html')
else:
response = "用户名或密码错误"
return HttpResponse(response)
#return redirect('/index/')
except:
return redirect('/index/')
def index(req):
try:
req.session['username']
print req.session.session_key
return render_to_response('main.html')
except:
return render_to_response('index.html')
![](https://img-blog.csdn.net/20180730083339950?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW95YW5namlhbjcyNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![](https://img-blog.csdn.net/20180730083402740?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW95YW5namlhbjcyNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![](https://img-blog.csdn.net/20180730083419203?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW95YW5namlhbjcyNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)