Access from a dictionary in flask via POST

Asked

Viewed 76 times

0

How could I access a dictionary element using POST in flask? I have lists to simulate a comic and through the POST, I would like to try to access them.

Function code:

@disciplina_ofertada_app.route('/disciplina_ofertada', methods = ["POST", "GET"])
def nova_disciplina_ofertada():
        nova_disciplina_ofertada = request.get_json()
        Disciplina_ofertada.append(nova_disciplina_ofertada)
        return jsonify(Disciplina_ofertada)

JSON used in POST:


{

    "id": 39104, 
    "id_disciplina":"Disciplina[0]['id']",
    "id_professor":"Professor[0]['id']",
    "ano":2018, "semestre": 2,
    "turma": "3C",
    "id_curso":"Curso[0]['id']",
    "data": "20/12/2019"

}

With this code it returns the index as a string and not the element I’m trying to access.

  • Have you solved it? This way you are trying to do it is not the right way. Apparently Disciplina is an array. Where is this array? Where do you declare? What value do you want to search for?

  • I managed to solve yes, I wanted the literal value, to do some tests. I managed using literal_eval.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.