本文整理匯總了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!")