'How To Transfer HTML Lists To Flask Python With The Method POST?

This is the function I call in python using flask:

@app.route('/display', methods=["GET", "POST"])
def display_list():

if request.method == "POST":
    data = request.form.to_dict(flat=False)
    print(data["list"])

return render_template("ListDisplay.html", list=["Cat", "Dog", "Cow"])

This is the relevant code from the HTML file ListDisplay.html:

<form name="list action" method="POST" action="">
<input type="hidden" value={{list}} name="list">
</form>

When I print data["list"] I don't get the full list that I wanted. Instead, I get a weird string.



Sources

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

Source: Stack Overflow

Solution Source