I'm creating a page on a site to allow users to 'bid' on items similar to ebay. When I try to enter a number (dollar amount) on the item on the site (to enter a bid) I get the error: MultiValueDictKeyError at /new_bid/5
'total_bid.'
The problem seems to be total_bid = request.POST["total_bid"] and I think the system believes it's None. I'm not sure why it thinks it's None because when entering the bid on the site, a number really is in the box, so if I type 100 meaning $100 bid, maybe the code is not actually taking in that number? So on POST it thinks there is nothing there?
I also tried total_bid = request.POST.get["total_bid"] with the .get part and also received an error.
I also tried adding something like "if total_bid is not none:" but I'm not sure how to do that with the syntax because I would need to declare total_bid = to something first.
I'm new to Django so additional information on how this works would be so helpful. I've already read a lot of posts on this site about this and similar errors but I'm having some trouble understanding.
views.py
def new_bid(request, listingid):
if request.method == 'POST':
auction_to_add = Listings.objects.get(id=listingid)
total_bid = request.POST["total_bid"]
bid = Bid.objects.create(user=request.user, listingid=auction_to_add, bid=total_bid)
auction_to_add.bids.add(bid)
auction_to_add.last_bid = bid
auction_to_add.save()
return render(request, "auctions/listing.html", {
"id": listingid,
})
else:
return render(request, "auctions/listing.html", {
"id": listingid,
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…