Ady Rehman
Ady Rehman

Reputation: 21

How to receive an array from a HTML page on Flask back-end

I'm taking inputs in a HTML window and storing it in an array using JavaScript. I want to return that array to to my Flask server.

function createTable()
{
    var name = new Array();
    cn = window.prompt("Input number of features", 1);
    for(var c=0;c<cn;c++)  
    {
        fname = window.prompt("Input feature name", 1);
        name[c]= fname;
    }
}
<form action = "/data", align="center"> 
<button  class="btn btn-success"  STYLE="background-color: #800080;" onclick ="createTable()">Enter 
Details</button></a>
</form></body>

I'm using the following line to fetch it on Flask:

feature_names = request.form.get("name")

However, it does not seem to be working for me. I want to know if there is a way to get arrays from HTML to Flask.

Upvotes: 1

Views: 672

Answers (1)

T. Goncalves
T. Goncalves

Reputation: 351

You can use request.form.getlist('name[]') in your Flask application.

Upvotes: 1

Related Questions