When I create an add and click the button, it is supposed to take me to the browse ads page, instead it is rendering the contents of browse ads page in the createad url, such that as if there is 2 browse ads page, and when I refresh the page the same post request is processed again and there we go having multiple ads that are the same.
views.py:
@login_required(login_url='/login')
def createAd(request):
if request.method == "POST":
item = Ad()
item.seller = request.user.username
item.seller_contact = request.user.phone
item.title = request.POST.get('title')
item.description = request.POST.get('description')
item.starting_price = request.POST.get('starting_price')
item.category = request.POST.get('category')
item.condition = request.POST.get('condition')
try:
item.save()
except ValueError:
return render(request, "auctions/createAd.html", {
"message": "Invalid starting price"
})
ad = Ad.get_all_ads()
# products = Ad.objects.all()
empty = False
if len(ad) == 0:
empty = True
return render(request, "auctions/activeAds.html", {
"ads": ad, "empty": empty
})
#get
else:
return render(request, "auctions/createAd.html")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…