简体   繁体   中英

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM