0
import flask

app = flask.Flask(__name__)

@app.route("/")
def index():
    return "You need to login"

@app.route('/login', methods=['GET', 'POST'])
def login():
    query = flask.request.query_string   # query is printed in terminal
    login = flask.request.get('login')   # here getting AttributeError
    print query, login
    if flask.request.method == 'POST':
        return "User is {}, Password is {}".format(flask.request.form['login'],flask.request.form['password']) 
    else:
        return flask.render_template("login.html")


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

When I pass the url in browser http://127.0.0.1:5000/login?login=hello&password=1234, it says:

AttributeError: 'Request' object has no attribute 'get'
1
  • 2
    Docs suggest you need to use request.args.get('login'). Commented Jan 9, 2015 at 22:14

2 Answers 2

1

The error message is correct, the Flask request object has no such method.

Perhaps you wanted to use that on the request.args or request.values MultiDict object instead? MultiDict objects do have a .get() method:

login = flask.request.args.get('login')
Sign up to request clarification or add additional context in comments.

1 Comment

Will accecp ur ans soon, its telling 6 min to wait, till then +1
0

If you want to get all values in the MultiDict with the same key, then you should use list_of_values = flask.request.args.getlist('name_of_key').

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.