Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:17:10+00:00 2026-05-27T18:17:10+00:00

There is form with two <input type=submit> . But when i’m sending it, second

  • 0

There is form with two <input type="submit">. But when i’m sending it, second submit causes error.

layout:

<form action="{{ url_for('index') }}" method="post">
    <input type="submit" name="add" value="Like">
    <input type="submit" name="remove" value="Dislike">
</form>

main.py:

...
if request.method == 'POST':
    if request.form['add']:
        return redirect(url_for('index'))
    elif request.form['remove']:
        return redirect(url_for('index'))
...

First submit(add) works well, but second(remove)…:

Bad Request The browser(or proxy) sent a request that this server could not understand.

How can i fix this error?

UPD:

It was pretty simple:
request.form returns ImmutableMultiDict:

... 
if 'Like' in request.form.values():
     ...
elif 'Dislike' in request.form.values():
     ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:17:11+00:00Added an answer on May 27, 2026 at 6:17 pm

    As @Blubber points out, the issue is that Flask raises an HTTP error when it fails to find a key in the args and form dictionaries. What Flask assumes by default is that if you are asking for a particular key and it’s not there then something got left out of the request and the entire request is invalid.

    There are two other good ways to deal with your situation:

    1. Use request.form‘s .get method:

      if request.form.get('add', None) == "Like":
          # Like happened
      elif request.form.get('remove', None) == "Dislike":
          # Dislike happened
      
    2. Use the same name attribute for both submit elements:

      <input type="submit" name="action" value="Like">
      <input type="submit" name="action" value="Dislike">
      
      # and in your code
      if request.form["action"] == "Like":
          # etc.
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

html form <form action=upload.php method=POST enctype=multipart/form-data> <input type=file name=file /><p /><input type=submit value=Uplaod />
I have two buttons inside a form call: <% using (Html.BeginForm()) {%> <input type=submit
I currently have an input form. There are two entries for each input class
I have a form with two textboxes and a submit button. The second box
There is one form, inside the form there are many checkboxes. Two operations can
A Jquery Modal is called with two form elements. There is also an option
I've created two UserControls, a ValidationManager and a ValidationOutput. On a given form there
There are two objects. The Windows Form with a button and a progress bar,
Backdrop: There are two forms, the main application form and a form to edit
I am developing a student registration form in asp.net. there are two tables viz

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.