在Flask中,提交表单后重定向到其他路由时,将引发Error Response 302 (VFS connection does not exist)
。下面是我正在处理的一个小示例,其他路由中的其他重定向也引发了完全相同的响应。代码或重定向没有什么奇怪的,我缺少什么吗? (我正在使用AWS Cloud9)
@app.route('/data/import-data', methods=['GET', 'POST'])
def csv_import():
if request.method == "POST":
#fetch file, some logical tests, parse to pandas df and session data - this works all fine and well
return redirect(url_for('map_fields')) #error occurs here
return render_template('data-import-data.html')
@app.route('/data/import-data/map-fields', methods=['GET', 'POST'])
def map_fields():
#get data from session data
if request.method == "POST":
#continue to work with the session data
return redirect(url_for('data_table'))
return render_template('data-import-map-fields.html')
用于第一个路由的表单的HTML,该表单重定向到另一个路由
<form class="" action="/data/import-data" method="POST" enctype=multipart/form-data>
<div class="position-relative form-group"><label for="exampleFile" class="">File</label>
<input name="csvfile" type="file" class="form-control-file">
<small class="form-text text-muted">Max. file size 1.5MB(Mega-Bytes). Accepted file type .csv only. </small>
</div>
<div class="position-relative row form-check">
<button hrefname="csvuploadbutton" class="mb-2 mr-2 btn btn-primary btn-lg btn-block" type="submit">Proceed
</button>
</div>
</form>