本文整理汇总了Python中forms.UserCreateForm.error_class方法的典型用法代码示例。如果您正苦于以下问题:Python UserCreateForm.error_class方法的具体用法?Python UserCreateForm.error_class怎么用?Python UserCreateForm.error_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UserCreateForm
的用法示例。
在下文中一共展示了UserCreateForm.error_class方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import error_class [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)