本文整理汇总了Python中accounts.forms.UserRegistrationForm.add_error方法的典型用法代码示例。如果您正苦于以下问题:Python UserRegistrationForm.add_error方法的具体用法?Python UserRegistrationForm.add_error怎么用?Python UserRegistrationForm.add_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.forms.UserRegistrationForm
的用法示例。
在下文中一共展示了UserRegistrationForm.add_error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from accounts.forms import UserRegistrationForm [as 别名]
# 或者: from accounts.forms.UserRegistrationForm import add_error [as 别名]
def register(request):
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
if form.is_valid():
try:
customer = stripe.Customer.create(
email=form.cleaned_data['email'],
card=form.cleaned_data['stripe_id'], # this is currently the card token/id
plan='REG_MONTHLY',
)
if customer:
user = form.save() # save here to create the user and get its instance
# now we replace the card id with the actual user id for later
user.stripe_id = customer.id
user.subscription_end = arrow.now().replace(weeks=+4).datetime # add 4 weeks from now
user.save()
# check we saved correctly and can login
user = auth.authenticate(email=request.POST.get('email'),
password=request.POST.get('password1'))
if user:
auth.login(request, user)
messages.success(request, "You have successfully registered")
return redirect(reverse('profile'))
else:
messages.error(request, "unable to log you in at this time!")
except stripe.error.CardError, e:
form.add_error(request, "Your card was declined!")