Python Flask : request.form, how to get specific value of key?

Question:

with Flask, i m a newbie, so my question is probably stupid. But I cannot understand why the page ‘/result’ is displaying "{resulte}" and not the input from field "Name".

I just want the page "result" to show what the user entered in the field "Name".

from flask import Flask, render_template, request
app=Flask(__name__)

@app.route('/')
def student():
    return render_template('testperso.html')

@app.route('/result', methods=['POST','GET'])
def result():
    if request.method=='POST':
        result=request.form['Name']
        return render_template('resultperso.html',resulte=result)
    
if __name__=="__main__":
    app.run(debug=True)

First HTML Page with Form:

<html>
   <body>
      <form action = "http://localhost:5000/result" method = "POST">
         <p>Name <input type = "text" name = "Name" /></p>
         <p>Physics <input type = "text" name = "Physics" /></p>
         <p><input type = "submit" value = "submit" /></p>
      </form>
   </body>
</html>

Second HTML with result :

<!doctype html>
<html>
   <body>
      <table border = 1>
        <h1>{resulte}</h1>
      </table>
   </body>
</html>

Thanks !

Asked By: Meriole

||

Answers:

You have to double your { delimiter.

<!doctype html>
<html>
   <body>
      <table border = 1>
        <h1>{{ resulte }}</h1>
      </table>
   </body>
</html>
Answered By: WebPrograme

You can check here about the statements, expressions and comments.
its the official documentation.

Answered By: erdoganb
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.