Python/Django"if语句"语法不正确?

fil*_*d13 0 python django if-statement syntax-error

for cart_item in cart_products:
    if **cart_item.**product.id = p.id:
        # update the quantity if found
        cart_item.augment_quantity(quantity)
        product_in_cart = True
if not product_in_cart:  
    # create and save a new cart item
    ci = CartItem()
    ci.product = p
    ci.quantity = quantity
    ci.cart_id = _cart_id(request)
    ci.save()
Run Code Online (Sandbox Code Playgroud)

我刚刚把我的购物车放在一起,这是一个简单的逻辑,检查以确保该项目不在某人的购物车中,以防他们试图再次错误地添加它.错误在粗体部分中出现... a :期望而不是a . 服务器抛出错误并且eclipse正在捕获语法错误.

为什么点语法会破坏if语句?如果需要更多上下文,请告诉我,但我猜我只是没有正确理解if语句的语法要求.

wRA*_*RAR 5

Python中的比较运算符==不是=.