Nakul Pathak
Nakul Pathak

Reputation: 109

Shopify python API command working in html view but not in views.py file

Provided this python code for a Shopify app:

with request.user.session:
    products = shopify.Product.find()    
for product in products:
    if product.variants.0.inventory_management:
        make_call()

So, when I use product.variants.0.inventory_management in my view file called "home.html", it displays the value "shopify" which makes sense. But when I use the exact same thing in the code example above I get a syntax error and my django app shows the error log. How do I fix this?

Upvotes: 0

Views: 60

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599490

variants is presumably a list. In python you use square brackets to index a list:

if product.variants[0].inventory_management:

Upvotes: 1

Related Questions