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


Python UserCreateForm.errors['__all__']方法代码示例

本文整理汇总了Python中forms.UserCreateForm.errors['__all__']方法的典型用法代码示例。如果您正苦于以下问题:Python UserCreateForm.errors['__all__']方法的具体用法?Python UserCreateForm.errors['__all__']怎么用?Python UserCreateForm.errors['__all__']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UserCreateForm的用法示例。


在下文中一共展示了UserCreateForm.errors['__all__']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user

# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import errors['__all__'] [as 别名]
def create_user(request):
    context = {}
    context_instance = RequestContext(request)
    form = UserCreateForm(request.POST or None)
    context['form'] = form
    
    if request.user.is_authenticated():
        return redirect('/user/dashboard')

    if request.method == 'POST' and form.is_valid():
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        phone = form.cleaned_data['phone']
        try:
            users_manager.create_user(first_name, last_name, username, password, email, phone)
            # authenticate and login
            user = authenticate(username=username, password=password)
            login_auth(request, user)
            return redirect('/user/dashboard')
        except Exception as exc:
            # 400
            form.errors['__all__'] = form.error_class(["Error: %s" % exc.message])

    # GET / POST with invalid input
    return render_to_response('user/create.html', context, context_instance=context_instance)
开发者ID:wormangel,项目名称:bandontherun,代码行数:30,代码来源:views_user.py


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