Like in other web scripting, flask also have GET and POST method to pass data.

To catch form data we need request object


from flask import Flask,request

Flask used different approach for GET and POST.

For GET request.


request.args.get('form-element-name', '')

For POST request.


request.form['form-element-name']

If you not follow the above for get and post you will get bad request error from flask server as response. So please careful in get and post.

Here i created a form with name and email using jquery and bootstrap.

flask-get-reg  

 

Example for GET:

Front end to display registration form.


@app.route("/get-reg")
def getreg():
    return render_template('getreg.html')

To catch the data present in the form in get method.


@app.route('/save-get',methods=['POST', 'GET'])
def saveget():
    if request.method=='GET':
       a=request.args.get('name', '')
       b=request.args.get('email', '')
       return "Name : "+a+" ,  Email :  "+a
    else:
        return "Not get method"

  Example for POST:

Front end to display registration form.


@app.route("/post-reg")
def postreg():
    return render_template('postreg.html')

To catch the data present in the form in post method.


@app.route('/save-post',methods=['POST', 'GET'])
def savepost():
    if request.method=='POST':
       a=request.form['name']
       b=request.form['email']
       return "Name : "+request.method+"  "+a+"    "+b
    else:
        return "error"

  After catching the form values, you can process the data and save into database of your choice.