'Is there a way to link function to button in Flask?

I would like to create a button to download the data contained in the table of my HTML page. First of all I thought of saving the data in a table in my database and then create a function that can be called up when the button is clicked (I specify that I would not want to be directed to any page and therefore to remain in the same where the button is). How can I link this function to the button? I tried using onClick() but it doesn't work.

This is the HTML code

<form method="GET" align="center" >
        <button onclick="download_file()" id="download-button" class="btn btn-primary btn-lg active" type="submit">Download Table</button>
    </form>

Thanks to everyone



Sources

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

Source: Stack Overflow

Solution Source