本文整理匯總了Python中users.forms.ProfileForm._errors["email"]方法的典型用法代碼示例。如果您正苦於以下問題:Python ProfileForm._errors["email"]方法的具體用法?Python ProfileForm._errors["email"]怎麽用?Python ProfileForm._errors["email"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類users.forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm._errors["email"]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
# 需要導入模塊: from users.forms import ProfileForm [as 別名]
# 或者: from users.forms.ProfileForm import _errors["email"] [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))