当前位置: 首页>>代码示例>>Python>>正文


Python UserRegistrationForm.add_error方法代码示例

本文整理汇总了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!")
开发者ID:PatrickMonks,项目名称:we_are_social_blog,代码行数:35,代码来源:views.py


注:本文中的accounts.forms.UserRegistrationForm.add_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。