Answer the question
In order to leave comments, you need to log in
How to make forms for a web application in Flask?
In a Flask app, I'm fetching from a database. I analyze the sample, in the template I turn it into a table and display it on the screen.
It is necessary to select some lines from what is displayed on the screen and send them for further processing in the functions that the user selects by clicking on buttons or links.
The difficulty is that I do not know how to correctly implement the selection of some of these lines and their subsequent transfer to the function for processing and output.
How I'm trying to act:
Option 1 - I create a form in the template and dynamically generate a checkbox for each line. What to do next? How to use it and whether to use it at all.
Option 2 - Use wtforms, it allows you to dynamically create forms with the same checkboxes, but there is only one submit button.
Apparently I'm missing a theory. I would be grateful for examples of how to do this and for a description of how to work with form data. I would like to see how to organize web applications for data manipulation in general, what technologies to use.
Thank you!
Answer the question
In order to leave comments, you need to log in
You are missing jQuery:
$('.my-action').on('click', function() {
// Список выбранных checkbox ов
var $checkboxes = $('.my-table').find(':checkbox:checked');
// Формируем массив пар ключ-значение
var data = $checkboxes.serializeArray();
// Отправляем данные на сервер
$.post('/server/action', data, function(response) {
/* Обрабатываем ответ /*
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question