Flask Request Object II - Form



vi templates/record.html

<!doctype html>
    <table border = 1>
      {% for key, value in input.iteritems() %}

          <th> {{ key }} </th>
          <td> {{ value }} </td>

      {% endfor %}

vi templates/friend.html

    <form action = "http://<ip/url>:5000/record" method = "POST">
       <p>Name <input type = "text" name = "name" /></p>
       <p>Age <input type = "text" name = "age" /></p>
       <p>Higher <input type = "text" name = "higher" /></p>
       <p>Weight <input type ="text" name = "weight" /></p>
       <p><input type = "submit" value = "submit" /></p>

vi friend_rec.py
from flask import Flask, render_template, request
ap = Flask(__name__)

def friend():
  return render_template('friend.html')

@ap.route('/record',methods = ['POST', 'GET'])
def record():
  if request.method == 'POST':
    input = request.form
    return render_template("record.html",input = input)

if __name__ == '__main__':
  ap.run(host= '')
python friend_rec.py


Leave comments


Copyright(c) 2017 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved