本文整理汇总了Python中forms.LoginForm.clean方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.clean方法的具体用法?Python LoginForm.clean怎么用?Python LoginForm.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.clean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import clean [as 别名]
def login(request):
if request.method == 'POST': #check to see if form has been submitted
form = LoginForm(request.POST) #capture data
if form.is_valid(): #validate data
cleaned_data = form.clean()
username = cleaned_data['username']
password = cleaned_data['password']
if username and password:
try: #attempt to use email to login
currentuser = User.objects.get(email = username)
user = auth.authenticate(username = currentuser.username, password = password)
auth.login(request, user)
return HttpResponseRedirect('/')
except: #assume that an actual username has been entered
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
auth.login(request, user)
# Render home page.
return HttpResponseRedirect('/')
form = LoginForm()
return render(request, 'login.html', {'form': form, 'form_error':True})
else:
# Return to login page.
form = LoginForm()
return render(request, 'login.html', {'form': form, 'form_error':True})
else:
form = LoginForm() #load blank form
return render(request, 'login.html', {'form': form, 'form_error':False})
示例2: _login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import clean [as 别名]
def _login(request):
if request.user.is_authenticated():
return HttpResponseRedirect(request.META.get('HTTP_REFERER','/'))
if request.method == 'GET':
referer = request.META.get('HTTP_REFERER','/')
if not 'accounts' in str(referer) :
request.session['referer'] = referer
else :
request.session['referer'] = '/'
form = LoginForm()
return render('login.html', RequestContext(request, {'form': form}))
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
data = form.clean()
user = auth.authenticate(username=data['username'], password=data['password'])
if user is not None and user.is_active:
auth.login(request, user)
next = request.GET.get('next') or request.session['referer'] or '/'
return HttpResponseRedirect(next)
return render('login.html', RequestContext(request, {'form':form, }))
示例3: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import clean [as 别名]
def login(request):
if request.method == 'POST': #check to see if form has been submitted
form = LoginForm(request.POST) #capture data
if form.is_valid(): #validate data
cleaned_data = form.clean()
username = cleaned_data['username']
password = cleaned_data['password']
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
auth.login(request, user)
# Render home page.
incorrectPassword = 0
return HttpResponseRedirect('/')
else:
# Return to login page.
incorrectPassword = 1
form = LoginForm()
return render(request, 'login.html', {'form': form, 'incorrectPassword': incorrectPassword})
else:
incorrectPassword = 0
form = LoginForm() #reload blank form
return render(request, 'login.html', {'form': form, 'incorrectPassword': incorrectPassword})