Answer the question
In order to leave comments, you need to log in
How to display information that came from the front-end in Flask's back-end?
Good afternoon, I created an Ajax request to the server with information. So, this information comes, but I need to accept it on the server and, let's say, output it somewhere, how is it done in Flask? Maybe there will be examples?
Answer the question
In order to leave comments, you need to log in
First, you should check what is being formed in $data
, there is most likely heresy. And in general it is not clear why such body movements, if you can simply:
$('#log-form').submit(function(event) {
event.preventDefault();
$.post($(this).attr('action'), $(this).serialize(), function(result) {
// Обрабатываете ответ от бэкенда как вам угодно
});
});
from flask import jsonify
from flask import request
@app.route('/', methods=['POST'])
def form_handler():
if request.form.get('login') == 'admin':
if request.form.get('pass') == 'qwerty':
return jsonify({'type': 'success', 'msg': 'Привет, Админ!'})
return jsonify({'type': 'error', 'msg': 'Неправильное имя пользователя или пароль'})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question