开发者

Cannot seem to delete an object number

开发者 https://www.devze.com 2023-02-11 23:12 出处:网络
I seem to have a problem deleting order numbers in Django. In my views, there is an order number equals to some pk value. There is also a submit button which should delete this number in the template.

I seem to have a problem deleting order numbers in Django. In my views, there is an order number equals to some pk value. There is also a submit button which should delete this number in the template. Unfortunately it is doing nothing (not deleting).

For some reason I thought these changes would delete an object, but it's still not working.

Basically I have this.

order = models.Order.objects.get(pk=1219)
if request.POST.get开发者_JAVA百科('delete'):
    order.delete()

And in my template I have this.

<input type="submit" name="delete" value="Delete" >


Got the answer. :) had

order = models.Order.objects.get(pk=1219)
if request.POST.get('delete'):
    order.delete()

in the wrong view! Can't believe I was this stupid.


In the second line you are initializing order with a tuple. In the fourth line you call delete() on that object.

I don't know, if that is what you intended. I cannot make any more sense out of what you wrote. Maybe you could give us some more detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消