app*_*ief 8 python flask wtforms flask-wtforms
我有一个收集信用卡信息的注册表.工作流程如下:
这是表单提交代码:
def register():
form = RegistrationForm()
if form.validate_on_submit():
user = User(
[...]
)
db.session.add(user)
#Charge
amount = 10000
customer = stripe.Customer.create(
email=job.company_email,
card=request.form['stripeToken']
)
try:
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Registration payment'
)
except StripeError as e:
***I want to raise a form validation error here if possible.***
db.session.commit()
return redirect(url_for('home'))
return render_template('register.html', form=form)
Run Code Online (Sandbox Code Playgroud)
app*_*ief 24
我通过手动将错误添加到我想要的字段来解决它.
它看起来像那样
try:
[...]
except StripeError as e:
form.payment.errors.append('the error message')
else:
db.session.commit()
return redirect(url_for('home'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7951 次 |
| 最近记录: |