Shopify python API 命令在 html 视图中有效,但在 views.py 文件中无效
Shopify python API command working in html view but not in views.py file
为 Shopify 应用提供此 python 代码:
with request.user.session:
products = shopify.Product.find()
for product in products:
if product.variants.0.inventory_management:
make_call()
因此,当我在名为 "home.html" 的视图文件中使用 product.variants.0.inventory_management 时,它会显示有意义的值 "shopify"。但是当我在上面的代码示例中使用完全相同的东西时,我得到一个语法错误并且我的 django 应用程序显示错误日志。我该如何解决这个问题?
variants
大概是一个列表。在 python 中,您使用方括号来索引列表:
if product.variants[0].inventory_management:
为 Shopify 应用提供此 python 代码:
with request.user.session:
products = shopify.Product.find()
for product in products:
if product.variants.0.inventory_management:
make_call()
因此,当我在名为 "home.html" 的视图文件中使用 product.variants.0.inventory_management 时,它会显示有意义的值 "shopify"。但是当我在上面的代码示例中使用完全相同的东西时,我得到一个语法错误并且我的 django 应用程序显示错误日志。我该如何解决这个问题?
variants
大概是一个列表。在 python 中,您使用方括号来索引列表:
if product.variants[0].inventory_management: