【发布时间】:2021-04-01 12:34:54
【问题描述】:
我有一个问题,我无法从 html 获得 POST
日志:
127.0.0.1 - - [01/Apr/2021 00:51:25] "←[37mGET /main?user=adasd&pass=123123 HTTP/1.1←[0m" 200 -
127.0.0.1 - - [01/Apr/2021 00:51:25] "←[36mGET /static/css/index.css HTTP/1.1←[0m" 304 -
127.0.0.1 - - [01/Apr/2021 00:51:25] "←[36mGET /static/js/index.js HTTP/1.1←[0m" 304 -
我已经搜索了stackoverflow&google,但仍未找到解决方案,
Flask receiving no data for HTML POST
Flask: Not able to receive HTML form POST data
Flask: Tutorial for MySql , just take a look on POST in html
index.html
...
<form action="{{url_for('enter')}}" methods="POST" autocomplete="off">
<p>Username:</p><input type="text" name='user'><br>
<p>Password:</p><input type="password" name='pass'><br><br><br>
<input type='submit' value='Enter'>
<input type='button' onclick="location.href='{{url_for('register')}}'" value='Register Here'>
</form>
...
main.py
@app.route('/',methods=['GET','POST'])
def index():
return render_template('index.html')
@app.route("/main",methods=["POST","GET"])
def enter():
app.logger.info("main "+request.method) # return GET
if request.method == "POST":
username = request.form.get("user")
password = request.form.get("pass")
app.logger.info(username) # returns None
app.logger.info(password) # returns None
return render_template('enter.html')
if request.method == "GET":
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True,host='localhost', port=5000)
我如何运行我的代码
在 Powershell 上 python main.py
注意:ImmutableMultiDict([])
【问题讨论】: