Flask Request Object

  • In the client-server architecture, the request object contains all the data that is sent from the client to the server.
  • Now we will discuss the Request object and its important attributes
    • Form : Contains the key-value pair of form parameters and their values.
    • Args : It is the part of the URL which is specified in the URL after question mark (?).
    • Cookies : It is saved at the client-side to track the user session.
    • Files: It contains the data related to the uploaded file.
    • Method: It is the current request method (get or post).

Form data retrieval on the template

  • The data filled in this form is posted to the /success URL which triggers the print_data() function.
  • print_data() collects all the data from the request object and the renders the result_data.html file which shows all the data on the web page.
 Flask Object

Flask Request Object


from flask import *  
app = Flask(__name__)  
def customer():  
   return render_template('customer.html')  
@app.route('/success',methods = ['POST', 'GET'])  
def print_data():  
   if request.method == 'POST':  
      result = request.form  
      return render_template("result_data.html",result = result)  
if __name__ == '__main__':  
   app.run(debug = True)  


       <h3>Register the customer, fill the following form.</h3>  
      <form action = "http://localhost:5000/success" method = "POST">  
         <p>Name <input type = "text" name = "name" /></p>  
         <p>Email <input type = "email" name = "email" /></p>  
         <p>Contact <input type = "text" name = "contact" /></p>  
         <p>Pin code <input type ="text" name = "pin" /></p>  
         <p><input type = "submit" value = "submit" /></p>  


<!doctype html>  
      <p><strong>Thanks for the registration. Confirm your details</strong></p>  
      <table border = 1>  
         {% for key, value in result.items() %}  
               <th> {{ key }} </th>  
               <td> {{ value }} </td>  
         {% endfor %}  


  • To run this application, we must first run the script.py file using the command python script.py.
 Flask Object

Flask Object

  • Now, hit the submit button. It will transfer to the /success URL and displays the data entered at the client.
 Flask Object1

Flask Object

If you want to learn about Python Course , you can refer the following links Python Training in Chennai , Machine Learning Training in Chennai , Data Science Training in Chennai , Artificial Intelligence Training in Chennai

Related Searches to Flask Request Object

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.