我的应用有一个奇怪的问题。
我正在做的是: 我在JS(客户端)中生成一个csv文件,然后将其发送到flask,然后在其中使用python脚本过滤该文件,然后将其返回给客户端。
除最后一部分外,其他所有功能都非常有效。当涉及到返回render_template 时,它只是跳过了这一部分。这很奇怪,因为它位于 if request.method =='POST'内部。我在 if request.method =='POST'中打印了这些值,然后可以在服务器端看到这些值。
烧瓶路线.py:
@app.route('/update_file',methods=['GET','POST'])
@login_required
def update_file():
'''Opens the filtered_file page but with updated file'''
clicked = None
if request.method == 'POST':
clicked = io.StringIO(request.form['data'])
file_to_filter = pd.read_csv(clicked,sep=',',engine='python',encoding='utf_8_sig')
table1 = update_csv(file_to_filter)
print(table1)
table2 = table1.to_html(classes='my_class" id = "my_id')
return render_template('3_filtered_file.html',data=table2)
这就是我在html模板上显示它的方式:
<div class="table-responsive">
{{data | safe}}
</div>
我已经对客户端上载的文件进行了类似的操作,效果很好,但是这个错误有一个我似乎找不到的错误:/
编辑: 这是我发送ajax rquest的JS:
//On Update click renders table to csv,activates the be_filter and reopens it in the filtered_file.html
var isClicked;
jQuery("#update").on('click',function(){
var response = confirm('Are you sure you want to UPDATE rows ?');
if(response == true){
isClicked = $('#my_id').table2csv();
$.ajax({
type:'POST',url:"{{url_for('update_file')}}",data: {'data': isClicked}
});
//window.location.href='/update_file';
}else{
return false;
}
});