Django 属性错误:';元组';对象没有属性';条纹客户id';
我在django应用程序中尝试使用stripe api提交购买时收到以下错误 第115行,邮寄 如果userprofile.stripe\u客户\u id!=''并且userprofile.stripe\u customer\u id不是None:AttributeError:'tuple' 对象没有属性“stripe\u customer\u id”[09/Oct/2019 19:18:26] “POST/api/checkout/HTTP/1.1”500 16291 一切都正常,直到我根据我的要求做了修改 这是第115行:Django 属性错误:';元组';对象没有属性';条纹客户id';,django,stripe-payments,Django,Stripe Payments,我在django应用程序中尝试使用stripe api提交购买时收到以下错误 第115行,邮寄 如果userprofile.stripe\u客户\u id!=''并且userprofile.stripe\u customer\u id不是None:AttributeError:'tuple' 对象没有属性“stripe\u customer\u id”[09/Oct/2019 19:18:26] “POST/api/checkout/HTTP/1.1”500 16291 一切都正常,直到我根据我
if userprofile.stripe_customer_id != '' and userprofile.stripe_customer_id is not None:
customer = stripe.Customer.retrieve(
userprofile.stripe_customer_id)
customer.sources.create(source=token)
你在这里发布的代码太多了
问题在于:
userprofile = UserProfile.objects.get_or_create(user=self.request.user)
返回元组:(对象,已创建)
。您已将整个元组分配给userprofile
变量
由于您不关心创建的
,请将其指定给一次性名称:
userprofile, _ = UserProfile.objects.get_or_create(user=self.request.user)