Django,值错误:尝试从多方对象中删除对象时,int()的无效文字的基数为10:''”>

问题描述 投票:0回答:1

我正在使用Django和Wagtail CMS在一个样机电子商务网站上工作。我在将商品删除到购物车应用程序时遇到问题。

我正在使用POST方法,该方法会根据产品ID更新购物车。如果购物车中的对象:删除其他:添加,它可以作为切换。它在产品页面上正常工作,但是当我尝试在购物车页面上删除时,我在/ cart / update /处收到ValueError以10为底的int()的无效文字:''好像没有通过产品ID?

这是触发POST方法的按钮的HTML

<form method='POST' action='{% url "cart:update" %}' class="form"> {% csrf_token %}
        <input type="hidden" name="product_id" value="{{ self.id }}" />
        {% if incart %}
        <button type="submit" class="btn btn-danger btn-md my-0 p btn-sm" type="submit">
            Remove
        </button>
        {% else %}
        <button type="submit" class="btn btn-primary btn-md my-0 p" type="submit">Add
            to cart
            <i class="fa fa-shopping-cart"></i>

        </button>
        {% endif %}


</form>

{{ self.id }}变量来自产品页面模型。使用a页模型。

页面模型

class ProductDetailPage(Page):

    def get_url(self):
        return self.url


    productImage = models.ForeignKey(
        "wagtailimages.Image",
        blank = False,
        null = True,
        on_delete = models.SET_NULL
    )

    productPrice = models.FloatField(
        null = False,
        blank = False,
        default = 0

    )

    content_panels = Page.content_panels + [
        ImageChooserPanel("productImage"),
        FieldPanel("productPrice")
    ]

这是我的购物车视图

def cart_update(request):
    product_id = request.POST.get('product_id')
    if product_id is not None:
        product_obj = Product.objects.get(id=product_id)
        cart_obj, new_obj = Cart.objects.new_or_get(request)
        if product_obj in cart_obj.products.all():
            cart_obj.products.remove(product_obj)
        else:
            cart_obj.products.add(product_obj)
    return redirect("cart:home")
    

我正在使用Django和Wagtail CMS在一个样机电子商务网站上工作。我在将商品删除到购物车应用程序时遇到问题。我正在使用POST方法,该方法根据产品ID更新购物车。它...

django post cart wagtail
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.