Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!