'Call function with a click of a button flask

Im very new to flask and im trying to convert a python tkinter gui app to web. As you can understand i have all the functions made so it would be great if a could call them and pass variables with a single click of a button.

for example:

get_sub_menu is a list generated by a query to the db where it stores [('1','name1'),('2','name2'),('3','name3')]

mod[0] = id

mod[1] = name

html file:

<html><head></head><body>

{% for mod in get_sub_menu %}
<button type="submit">{{ mod[1] }}</button>
{% endfor %}

when i click in one button he should submit the id(mod[0]) and call function(myid) where myid would be the id submited when the button is clicked in order to generate the second list of buttons.

{% for item in function(mod[0]) %}
<button type="submit">{{ item[1] }}</button> #function(mod[0])
{% endfor %}

</body><html>

py file:

def function(myid):

    select * from table where id=myid

    res = cursor.fetchall()

    return res 

should i do this with request or args? can anyone help me with bouth questions in order for me to learn and understand why one is better than the other?



Solution 1:[1]

lol maybe you should leave python and dedicate yourself to

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PyGood