Search code examples
htmlpython-3.xformsflaskwebserver

How To Get image <input> from HTML in flask


Quick question as I can't really find this anywhere else.

If I had an input that is formed like this:

<input type="image" name="Text" value="text" src="{{ url_for('static', filename='images/icons/General/Post.svg') }}" />

How Can I retrieve this being pressed with request.form[]?

I get an KeyError with the following:

if request.method == "POST":
    if request.form["Text"] == "text":
        return render_template("PostText.html")

I know there is a similar way of retrieving data using <input type="submit" value="text"> but it doesn't work with the former.

Thanks!

Edit: fixed formatting and grammar.

TLDR: I can't detect an input with the type of image from flask in python.


Solution

  • According to mdn:

    for input elements of type image the value attribute should not be specified

    The value will always be None