当前位置: 首页>>代码示例>>Python>>正文


Python ProfileForm._errors["email"]方法代码示例

本文整理汇总了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))
开发者ID:kpx13,项目名称:vv,代码行数:53,代码来源:views.py


注:本文中的users.forms.ProfileForm._errors["email"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。