[Python] whenever i hit post request on my page then I cannot display the updated value from...

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    This is my code and inorder to fetch the correct result i have to either refresh or render the user.html again to reflect the changes. is there any way to do it more efficiently

    I tried rendering the same page again which gave me the correct solution but I think this is useless and unprofessional

    @app.route("/user",methods=["POST","GET"])
    def user():
    name=session["user"]
    mail=session["gmail"]
    animal=None
    if request.method =="POST":
    form_type=request.form.get("form_type")
    if form_type=="update_animal":
    flash("Animal's name has been updated")
    animal=request.form["animal"]
    session["animal"]=animal
    name=session["user"]
    usr_obj=users.query.filter_by(name=name).first()
    usr_obj.animal=animal
    gmail=usr_obj.email
    # print(usr_ obj.animal)
    db.session.commit()
    return render_template("user.html")

    Continue reading...

Compartilhe esta Página