本文整理汇总了Python中django.contrib.auth.forms.AuthenticationForm._errors方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm._errors方法的具体用法?Python AuthenticationForm._errors怎么用?Python AuthenticationForm._errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.AuthenticationForm
的用法示例。
在下文中一共展示了AuthenticationForm._errors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import _errors [as 别名]
def register(request):
c = get_common_context(request)
register_form = ProfileForm()
c['register_form'] = register_form
auth_form = AuthenticationForm()
c['auth_form'] = auth_form
if request.method == "POST":
if request.POST['action'] == 'register':
register_form = ProfileForm(request.POST, request.FILES)
if register_form.is_valid():
error = False
if len(User.objects.filter(username=register_form.data.get('email'))):
register_form._errors["email"] = ErrorList([u'Такой емейл уже зарегистрирован.'])
error = True
if not error:
email = register_form.data.get('email')
u = User(username= email,
email=email,
first_name=register_form.data.get('fio'))
password = password_generator()
u.set_password(password)
u.save()
p = register_form.save(commit=False)
p.user = u
p.save()
user = auth.authenticate(username=email, password=password)
auth.login(request, user)
p.send(password)
return HttpResponseRedirect('/edu/')
c['register_form'] = register_form
elif request.POST['action'] == 'auth':
auth_form = AuthenticationForm(request.POST)
if auth_form.is_valid():
pass
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/edu/')
else:
auth_form._errors = {}
auth_form._errors["username"] = ErrorList([u'Неверный логин или пароль.'])
c['auth_form'] = auth_form
c['title'] = u'Регистрация'
return render_to_response('register.html', c, context_instance=RequestContext(request))