django - AttributeError:“元组”对象没有属性“stripe_customer_id”
问题描述
尝试在 django 应用程序中使用 stripe api 提交购买时,我收到以下错误。
第 115 行,如果 userprofile.stripe_customer_id != '' 并且 userprofile.stripe_customer_id 不是 None:AttributeError: 'tuple' object has no attribute 'stripe_customer_id' [09/Oct/2019 19:18:26] "POST /api/结帐/HTTP/1.1" 500 16291
一切正常,直到我根据22:33进行更改。
这是第 115 行:
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)
get_or_create
返回一个元组:(object, created)
. 您已将整个元组分配给userprofile
变量。
由于您不关心created
,请将其分配给一次性名称:
userprofile, _ = UserProfile.objects.get_or_create(user=self.request.user)
推荐阅读
- php - 页脚从 Woocommerce 挂钩加载链接
- javascript - 如何使用道具中的对象解构为功能性 React 组件声明类型?
- java - Data Studio 中是否有任何 REST API 可用于在 JAVA 中创建报告?
- angular - 在 HTTP 获取订阅方法中设置 Angular 类变量
- java - json反序列化有一些问题
- python - 从一个点找到坐标并在图中给出距离
- javascript - 如何为 javascript 对象设置动画?
- macos - 需要创建一个受限网络,其中 UDP 端口在 mac 中被阻止
- lua - 如何连续执行 for 循环而不是卡在单个重复函数上?
- python - 根据小时和分钟列表生成日期