skip to Main Content

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 !

2

Answers


  1. You have to double your { delimiter.

    <!doctype html>
    <html>
       <body>
          <table border = 1>
            <h1>{{ resulte }}</h1>
          </table>
       </body>
    </html>
    
    Login or Signup to reply.
  2. You can check here about the statements, expressions and comments.
    its the official documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search