How to get HTML Input using Python Flask How to get HTML Input using Python Flask flask flask

How to get HTML Input using Python Flask


Change your form method from GET to POST, as your route only specifies "POST", and will not accept any other requests of a different type:

<form method="POST">

Edit: if you wish to specify both methods, ensure that your route checks for the correct type of request currently being sent when the route is triggered:

@app.route('/', methods=['POST','GET'])def form_post():  if flask.request.method == 'POST'     userEmail = request.form['userEmail']     userPassword = request.form['userPassword']     return userEmail, userPassword  return flask.render_template('something.html')

Note, however, that you are creating your form on the home route ('/'). It may be best to return a link to the page that has the form code:

@app.route('/')def home():  return 'Welcome! <a href="/login">login here</a>'@app.route('/login', methods=['GET', 'POST']):  if flask.request.method == 'POST'    userEmail = request.form['userEmail']    userPassword = request.form['userPassword']    return flask.redirect('/')  return flask.render_template('form_filename.html')