Flask: ImmutableMultiDict has no attribute
I wrote a small flask file:
myapp.py
@APP.route('/login', methods=['GET','POST'])
def login():
return flask.render_template('login.html')
@APP.route('/loginNext', methods=['POST','GET'])
def loginNext():
user=request.form.username
passw=request.form.password
return str(user)+str(pass)
login.html
<form id="foo" method="post" action="/loginNext">
Username : <input type="text" name='username' value="admin">
Password : <input type="password" name='password' value="">
<input type="submit" name="submit" value="Submit">
</form>
When I try to execute request.form.username I get
* AttributeError: "ImmutableMultiDict" object has no "username" attribute *
I read about stackoverflow and other places but didn't work. I tried to do request.form.get ('username', None ') which didn't get the username.
+3
user3380728
source
to share
1 answer
<input type="text" name='username' value="admin">
was your file entry .html
to access the flask. It is done this way.
username = request.form['username']
and you get the data as username .. same for password.
+2
Suraj palwe
source
to share