你好,我正在用烧瓶在pyhton做一个项目,我假装介绍了一个txt并阅读了它。
此代码是home.html的一部分:
<input type="file" id="gameTXT" name="gameTXT" accept="txt">
<input type="submit" id="submitTXT" value="Submit">
这个是python的一部分:
@app.route("/")
def home():
return render_template('home.html')
我怎样才能拿到文件?我读到我需要把方法=['GET'],但我不知道把它放在哪里
我试着在app.route("/"(中放入方法=["GET"],但它不起作用,这是可以理解的。我希望得到文件
如果你想获取文件,你需要首先知道你的表单方法是什么,正如你提到的get,我假设是get。(但我插入POST只是以防万一(。
您需要创建函数,提到方法是GET,然后您需要获得发送的数据,即request.form['name']
获取Flask请求中接收的数据参考上文,您的代码应该是
@app.route("/", methods=['GET', 'POST'])
def home():
data = request.form['gameTXT']
### do whatever you want with data
return render_template('home.html')
尝试在route((中添加方法,如下所示:
@app.route("/", methods=["GET"])
def home():
return render_template('home.html')