How to get the name of a submitted form in Flask?

前端 未结 1 1774
抹茶落季
抹茶落季 2020-12-15 11:42

I\'m building a website using Flask, and on one page I\'ve got two forms. If there\'s a POST, I need to decide which form is being posted. I can of course deduct it from the

1条回答
  •  生来不讨喜
    2020-12-15 11:58

    There is no 'name of the form'. That information is not sent by the browser; the name attribute on

    tags is meant to be used solely on the browser side (and deprecated to boot, use id instead).

    You could add that information by using a hidden field, but the most common way to distinguish between forms posting to the same form handler is to give the submit button a name:

    
    

    and

    if 'form1' in request.form:
    

    but you could also use a field to include the means to distinguish between forms.

    0 讨论(0)
提交回复
热议问题