当我加载我的网站时,我收到错误400,我检查了所有内容,似乎没有任何结果。 感谢
错误:
错误请求
浏览器(或代理)发送了此服务器无法理解的请求。
代码的作用: 它需要用户输入,然后保存在文件中,以便跟踪用户从饮料机订购的内容
import flask
from flask import request
@app.route('/Half1File', methods=['POST'])
def Half1File():
print(request.form['projectFilepath'])
Name = request.form['projectFilepath']
print(Name)
file = open("Tab.txt", "a")
file.write('\n'+Name + ", Drink1Half")
return
print (Name)
@app.route("/Half1Tab")
def Half1Tab():
return """<html>
<form action="/Half1File" method="post">
Project file path: <input type="text" name="Name"><br>
<input type="submit" value="Submit">
</form>
</html>"""
答案 0 :(得分:0)
您必须修复表单中传递给request
的值的名称,并在return语句中提供一个视图(我使其 easy )。
import flask
from flask import request
app = flask.Flask(__name__)
@app.route('/Half1File', methods=['POST'])
def Half1File():
print(request.form)
print(request.form['Name'])
Name = request.form['Name']
print(Name)
file = open("Tab.txt", "a")
file.write('\n'+Name + ", Drink1Half")
return """<html><div>OK : {} </div></html>""".format(Name)
@app.route("/Half1Tab")
def Half1Tab():
return """<html>
<form action="/Half1File" method="post">
Project file path: <input type="text" name="Name"><br>
<input type="submit" value="Submit">
</form>
</html>"""