Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Python flask sending back undefined objects despite using jsonify and render_templates

I'm building a flask application and I want a python function to send back either a string or a template to my javascript code. Unfortunately, javascript can't seem to decode the objects my function is sending back despite using the jsonify and render_template functions. Below is my code: Python

@app.route('/rep_bot',methods=['GET','POST'])
def bot_rep_py():
    print("bot_rep_py lancée")
    if request.method=='POST':
        input_text=request.form["js_input"]
        print(input_text)
        output_list=get_response(input_text)
        print(output_list)
        if type(output_list) == list:
            return render_template('form_comp.html',data=map(json.dumps,output_list))
        else:
            print("entrée dans else")
            return jsonify('0') #si le métier n'est pas connu on renvoie 0 et on transmet le msg coté js
    else:
        return "erreur pas POST" 

JavaScript

function bot_rep_js(input) {
  console.log("bot_rep_js lancée")
  console.log(input)
  $.post("http://127.0.0.1:5000/rep_bot", 
  {js_input:input},
  function(data){return data;}
  );
  console.log("bot_rep_js finie")
}
And the console:
clickUpdate lancée
script.js:66 premier click
script.js:45 bot_rep_js lancée
script.js:46 devops
script.js:51 bot_rep_js finie
script.js:68 undefined

EDIT: problem came from the fact that the flask server didn't get enough time to solve my request so assigning the variables immediately made them "undefined"

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda