I'm newbie to flask,I have such a form:
<form class="form" action={{ url_for('/login') }} method="POST">
<input type="text" name="usename" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit" id="login-button">Login</button>
</form>
I use request.form()
and request.form.get()
to get submitted values,but the result is always the same**"GET / HTTP/1.1" 200 -**
@app.route('/login',methods=['POST','GET'])
def login():
name=request.form['usename']
password=request.form['password']
form_data=request.form.get('usename')
print name,password,form_data
return render_template('login.html')
And I try visiting /login
,it shows Bad Request.But when it is modified to such,it's ok.It seems my request
statement block is incorrect.
@app.route('/login',methods=['POST','GET'])
def login():
return render_template('login.html')