Siddhant Shah
Siddhant Shah

Reputation: 63

is there any way to stop from redirect to home page index.html?

The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?

On refresh This message is coming and the form data is again submited to the flask.How to stop this from happening?

@app.route("/register",methods=["Get"])
def register():
    if not request.form.get("name"):
        return("fails2")
    else:
        if(request.method=="Get"):
            return("good")
        else:
            file = open("registered.csv","a")
            writer = csv.writer(file)
            writer.writerow((request.form.get("name")))
            file.close()

            file = open("registered.csv","r")
            reader=csv.reader(file)
            students=list(reader)

            return render_template("Chat.html",students=students)
 <form action="/r" method="post"  onsubmit="post()"  name="reload" style="text-align:center;">
                    <p style="background-color:AQUA;">
                        <textarea name="name" style="height:45px;width:350px;font-size:14pt;"  placeholder="message......" ></textarea><br>
                        <button type="submit" onclick="submit()" style="position:relative;background-color:blue;color:white;font-size:14pt;width:25%;">Post</button>
                    </p>

                 </form>

Upvotes: 0

Views: 146

Answers (1)

Sarthak Dwivedi
Sarthak Dwivedi

Reputation: 209

You get the warning message every time you refresh the post request page. Although Your question isn't clear, but from what I understand. The way you can handle it would be to listen for post request and redirect back to request(form) page. This should prevent warning message and data from being resubmitted by refreshing.

Upvotes: 1

Related Questions