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 8580455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:50:03+00:00 2026-06-11T20:50:03+00:00

I have a form that posts a personId int to Flask. However, request.form[‘personId’] returns

  • 0

I have a form that posts a personId int to Flask. However, request.form['personId'] returns a string. Why isn’t Flask giving me an int?

I tried casting it to an int, but the route below either returned a 400 or 500 error. How can I get I get the personId as an int in Flask?

@app.route('/getpersonbyid', methods = ['POST'])
def getPersonById():
    personId = (int)(request.form['personId'])
    print personId
  • 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-06-11T20:50:05+00:00Added an answer on June 11, 2026 at 8:50 pm

    HTTP form data is a string, Flask doesn’t receive any information about what type the client intended each value to be. So it parses all values as strings.

    You can call int(request.form['personId']) to get the id as an int. If the value isn’t an int though, you’ll get a ValueError in the log and Flask will return a 500 response. And if the form didn’t have a personId key, Flask will return a 400 error.

    personId = int(request.form['personId'])
    

    Instead you can use the MultiDict.get() method and pass type=int to get the value if it exists and is an int:

    personId = request.form.get('personId', type=int)
    

    Now personId will be set to an integer, or None if the field is not present in the form or cannot be converted to an integer.


    There are also some issues with your example route.

    A route should return something, otherwise it will raise a 500 error. print outputs to the console, it doesn’t return a response. For example, you could return the id again:

    @app.route('/getpersonbyid', methods = ['POST'])
    def getPersonById():
        personId = int(request.form['personId'])
        return str(personId)  # back to a string to produce a proper response
    

    The parenthesis around int are not needed in Python and in this case are ignored by the parser. I’m assuming you are doing something meaningful with the personId value in the view; otherwise using int() on the value is a little pointless.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form that posts to an HttpPost action method, which returns
I have got a form that posts values to a page in a wizard.
I have a html form that posts to a new page on submit. If
I have a form that posts to a page. I want to display an
I have a html form that posts to a python script test.py. If someone
I have a form that posts to process.php. Process.php send all the data to
I'm building a page where I want to have a form that posts to
I have a simple HTML form that posts to a PHP page, which will
In an HTML-document, i want to have a (if possible: invisible) form that POSTs
If I have a form that's on page http://foo.com/get , but posts to http://foo.com/post

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.