def login_page(request): if request.user.is_authenticated(): # 判断用户是否已经登录 print 'aa' message = '你已经登陆' back = '/main_page/' return render_to_response('redirect.html', {'message': message, 'back':back}) if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): try: username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] user = au(username=username, password=password) # print username # print password if user is not None: # au:如果正确返回User对象,否则返回None if user.is_active: login(request, user) return HttpResponseRedirect('/main_page/%s' % user.username) else: print "你的帐号不能用" else: return render_to_response('home.html', {'wrong': True}) except Exception, e: # 某一项为空都会转到这里 print e # return render_to_response('login.html', RequestContext(request, {'wrong': True})) else: print "不合法填写表单" return render_to_response('home.html')
def login_page(request): if request.user.is_authenticated(): return render_to_response('index.html', RequestContext(request,{'existed':True})) if request.method == "POST": uf = UserForm(request.POST) try: uf.is_valid() username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] user = au(username=username, password=password) if user is not None: #au:如果正确返回User对象,否则返回None if user.is_active: login(request, user) return HttpResponseRedirect('/main_page/%s' % user.username) else: return render_to_response('login.html',{'wrong':True}) except Exception,e: #某一项为空都会转到这里 print e
def login_page(request): if request.user.is_authenticated(): return render_to_response('index.html', RequestContext(request, {'existed': True})) if request.method == "POST": uf = UserForm(request.POST) try: uf.is_valid() username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] user = au(username=username, password=password) if user is not None: #au:如果正确返回User对象,否则返回None if user.is_active: login(request, user) return HttpResponseRedirect('/main_page/%s' % user.username) else: return render_to_response('login.html', {'wrong': True}) except Exception, e: #某一项为空都会转到这里 print e