Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

python - I have some sort of weird bug that is affecting the functionality

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")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...