R
R
REDkiy2015-08-12 21:57:27
Flask
REDkiy, 2015-08-12 21:57:27

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

2 answer(s)
A
Alexander, 2015-08-13
@REDkiy

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) {
  /* Обрабатываем ответ /*
});
});

I think you will understand the data processing on the Flask side. :)

D
Dimonchik, 2015-08-12
@dimonchik2013

start with habrahabr.ru/post/194062
and a couple of books on Flask
ebooks24.org/9781449372620.html
ebooks24.org/9781783983407.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question