1

I am not able to pass data in Flask using GET Method.

I testing using web browser and it is showing null

from flask import Flask, request
import sqlite3
import json

app = Flask(__name__)


@app.route('/test', methods=['GET'])
def test():
    name = request.form.get('name')
    return json.dumps({'result' : name})

@app.route('/test2')
def test2():
    return json.dumps({'result' : "demo"})

if __name__ == '__main__':
    app.run(host='192.168.0.2', port=8090, debug=True)

When I am running in web browser with URL

  1. http://192.168.0.2:8090/test2

It is giving result

{"result": "demo"}

Which is correct.

  1. http://192.168.0.2:8090/test?name=rahul

It is giving result

{"result": null}

Which should be {"result": "rahul"}

Where I am making mistake ?

Rahul Kumar
  • 2,184
  • 3
  • 24
  • 46

1 Answers1

0

Use name = request.args.get('name')

Because you are testing the API using web browser URL you have to use args

When you are sending data from form you can use name = request.form.get('name')

Rahul Kumar
  • 2,184
  • 3
  • 24
  • 46