Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

406
Visualizações
Flask request.get_json() returning None when valid json data sent via post request

Building an app using flask. The app uses a table structure to display data. Part of its functionality is collecting the data from user specified table rows. To do this I have placed a button on each row that executes some js. The js collects the information from the row, uses JSON.stringify() to convert to json object and the issues the post request to the relevant flask url.

Logging the value of the jsonified object to the browser console from js file shows it is correctly formed. The post request contacts the correct route however the request.get_json() function returns a value of None in the method of that route.

I have set up a seperate route in flask for testing. Here is the relevant code

from javascript

    function do_some_work(e) {
        var row_data = get_table_row_data(e);
        row_data = JSON.stringify(row_data);
        console.log(row_data);
        $.post("test", row_data);
    }

get_table_row_data() simply returns an object with key:value pairs. The log shows the data is correctly formatted json.

And here is the python code

#TODO
@application.route('/test', methods=['GET', 'POST'])
def test():
    data = request.get_json()
    print("data is "+format(data))
    return redirect(url_for('index'))

Here data is coming up as None

any help much appreciated

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's request.json it will return a dictionary of the JSON data. To get a value you use request.json.get('value_name'). So your route will be like this

#TODO
@application.route('/test', methods=['GET', 'POST'])
def test():
    data = request.json
    print("data is " + format(data))
    return redirect(url_for('index'))
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda