[Python] How to pass id from flask app to mysql database

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a flask application that is connected to the MySQL database.


    NOTE

    database name = evaluation

    table name = evaluation

    columns = eval_id, eval_name, date
    ​

    I have an 'evaluation table' with field eval_id, eval_name and date in it.

    mysql> use evaluation;
    mysql> describe evaluation;
    +-----------+-------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +-----------+-------------+------+-----+---------+-------+
    | eval_id | int(11) | NO | PRI | NULL | |
    | eval_name | varchar(20) | NO | | NULL | |
    | date | datetime(6) | NO | | NULL | |
    +-----------+-------------+------+-----+---------+-------+


    How can I write an API to get a particular evaluation by its id? I tried the below, but it doesn't work.

    @app.route('/getEval/<int:eval_id>', methods=['GET'])
    def getEvalByID(eval_id):
    cur.execute('''select * from evaluation.evaluation where eval_id=eval_id''')
    res = cur.fetchall()
    return jsonify({'test':str(res)})


    How can I correct this and get only the evaluation based on the eval_id mentioned in the app.route.

    Continue reading...

Compartilhe esta Página