本文整理汇总了Python中accounts.models.User.create方法的典型用法代码示例。如果您正苦于以下问题:Python User.create方法的具体用法?Python User.create怎么用?Python User.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import create [as 别名]
def register(request):
user = None
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
#https://github.com/realpython/book3-exercises/blob/7dce6dbf77c62124cb0ef6d909cdd1a1afdc88de/django_ecommerce/payments/views.py
cd = form.cleaned_data
try:
with transaction.atomic():
user = User.create(cd['name'], cd['email'], cd['password'])
user.save()
except IntegrityError:
form.addError(cd['email'] + ' is already a member')
else:
request.session['user'] = user.pk
return HttpResponseRedirect('/')
#user = User(
#name=form.cleaned_data['name'],
# email=form.cleaned_data['email'],
#)
#ensure encrpyted password
#user.set_password(form.cleaned_data['password'])
#try:
# user.save()
#except IntegrityError:
# form.addError(user.email + ' is already a member')
#else:
# request.session['user'] = user.pk
# return HttpResponseRedirect('/')
else:
form = UserForm()
return render_to_response(
'accounts/register.html',
{
'form': form,
'user': user,
},
context_instance=RequestContext(request)
)