本文整理汇总了Python中forms.UserCreateForm.clean_username方法的典型用法代码示例。如果您正苦于以下问题:Python UserCreateForm.clean_username方法的具体用法?Python UserCreateForm.clean_username怎么用?Python UserCreateForm.clean_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UserCreateForm
的用法示例。
在下文中一共展示了UserCreateForm.clean_username方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_user
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import clean_username [as 别名]
def register_user(request):
template_name = 'kitchen/crispy.html'
if request.method == 'POST':
user_form = UserCreateForm(request.POST)
if user_form.is_valid():
username = user_form.clean_username()
password = user_form.clean_password2()
user_form.save()
user = authenticate(username=username,
password=password)
if user:
# save extra parameters - email
user.email = user_form.data['email']
user.save()
#ASK - may be we should init it only in one place - on login?
initUser(user)
login(request, user)
return redirect('account-list')
return render(request,
template_name,
{ 'form' : user_form })
args = {}
args.update(csrf(request))
args['form'] = UserCreateForm()
print args
return render(request, template_name, args)
示例2: signup
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import clean_username [as 别名]
def signup(request):
user_form = UserCreateForm(data=request.POST)
if request.method == 'POST':
if user_form.is_valid():
username = user_form.clean_username()
password = user_form.clean_password2()
user_form.save()
user = authenticate(username=username, password=password)
login(request, user)
return redirect('/')
else:
return index(request, user_form=user_form)
return redirect('/')
示例3: register
# 需要导入模块: from forms import UserCreateForm [as 别名]
# 或者: from forms.UserCreateForm import clean_username [as 别名]
def register(request):
if request.method == 'GET':
form = UserCreateForm()
return render_to_response("register.html", RequestContext(request, {"form": form, }))
else:
form = UserCreateForm(request.POST)
if form.is_valid():
username = form.clean_username()
password = form.clean_password2()
form.save()
user = authenticate(username=username, password=password)
login(request, user)
return HttpResponseRedirect("/")
else:
return render_to_response("register.html", RequestContext(request, {"form": form, "account_error": True }))