(This is probably a stupid question, so please put on your dumb shields!) I was a PHP programmer and am now learning Python + Flask. Recently, I had to struggle a lot with sending data through AJAX and returning a response. Finally, the code that worked was:
@app.route('/save', methods=['POST']) def save_subscriptions(): if request.method == 'POST': sites = request.form.get('selected') print(sites) sites = sites[0:-1] g.cursor.execute('UPDATE users SET sites = %s WHERE email = %s', [sites, session.get('email')]) g.db.commit() return json.dumps({'status': 'success'})
If I change return json.dumps({'status': 'success'}) to return 1 , I get an exception that int is not callable . First of all, I donβt understand who is trying to call this int and why? Secondly, in PHP it was often possible just to echo 1; , and that would be the answer of AJAX. Why doesn't return 1 work in Flask, then?
source share