本文整理汇总了Python中accounts.forms.LoginForm.errors['username']方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.errors['username']方法的具体用法?Python LoginForm.errors['username']怎么用?Python LoginForm.errors['username']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.errors['username']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import errors['username'] [as 别名]
def login(request):
"""Login. Looks up by username or email address."""
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
next_url = None
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
user = auth.authenticate(username=request.POST['username'],
password=request.POST['password'])
if not user:
try:
email_user = User.objects.get(
email__exact=request.POST['username'])
user = auth.authenticate(username=email_user.username,
password=request.POST['password'])
except User.DoesNotExist:
user = None
if user:
if user.is_active:
auth.login(request, user)
if 'next' in request.POST:
return HttpResponseRedirect(request.POST['next'])
else:
return HttpResponseRedirect(reverse('index'))
else:
form.errors['username'] = 'This user is not active yet, please try later.'
else:
form.errors['username'] = (
'username or email address not found and/or password wrong')
else:
form = LoginForm()
next_url = urllib.unquote_plus(request.GET.get('next', '')).decode('utf8')
return render(request, 'accounts/login.html', {'login_form': form,
'next': next_url})