Flask Request Object I - method

Client send the data to server as a global request object(must import request from FLASK)

some important attributes are below:
method − current request method
Form − dictionary object form parameters and their values
Cookies − dictionary object holding Cookie names and values
files − data pertaining to uploaded file
args − parsed contents of query string which is part of URL after a ? charter


GET: get the information stored on that page and send it
HEAD: get only interested in the headers, not the content of the page
POST: post information to that URL and that the server must ensure the data is stored and only stored once
PUT: server might trigger the store procedure multiple times by overwriting the old values more than once
PATCH: used to update partial resources(e.g. update one field)
DELETE: remove the information from the given location
OPTIONS: provides a quick way for a client to figure out which methods are supported by this URL

In HTML4 and XHTML1, the only methods a form can submit to the server are GET and POST,
but with JavaScript and future HTML standards you can use the other methods as well.



    <form action = "http://<ip/url>:5000/login" method = "post">

      <p>Enter Name:</p>
      <p><input type = "text" name = "nm" /></p>
      <p><input type = "submit" value = "submit" /></p>


from flask import Flask, redirect, url_for, request
app = Flask(__name__)

def success(
    return 'Welcome %s.' %

@app.route('/login', methods = ['POST', 'GET'])
def login():
    if request.method == 'POST':
       user = request.form['nm']
       return redirect(url_for('success', name_input=user))
       user = request.args.get('nm')
       return redirect(url_for('success',

if __name__ == '__main__':
python login.py

#use your browser open the login.html(must use general http since it's a text file with no route)
#or maybe save it at client and open it at local

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