1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How can I check if a value is inside a session in Flask and Jinja?

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I want to check if a value, for example the 'name' value, exists in a session in a Flask application I made, but it's not working.

    Python:



    @app.route("/add/<string: name>")

    def add(name):

    session["list"].append(name)

    return "Successful"

    @app.route("/list

    def list():

    cursor=mysql.connection.cursor()

    query="Select * From data where id=1"

    cursor.execute(query)

    data=cursor.fetchone()

    return render_template("list.html",data=data)


    HTML:



    {% if data.name in session["list"] %}

    There is

    {% else %}

    None

    {% endif %}


    Even if the data.name value is in the session, it goes into the else block

    Continue reading...

Compartilhe esta Página