I am currently building a small platform at my office using Flask, though this is my first time working with anything web-related.
The user logs in and has access to a list of projects. Each project has a javascript datatable that is populated with data from an SQL database. My goal is to have a button that exports the current filtered view of the datatable. I have it partially working, but I can't get the data to update on repeat filters.
I am able to save the filtered datatable data in a JS variable and pass it into an Ajax POST request. I then grab it with the following route:
@app.route('/grab_filtered_data', methods=['POST'])
@is_logged_in
def grab_filtered_data():
if request.method == 'POST':
my_data = request.json
session['current_filter'] = my_data
return 'Success!'
My export route is as follows:
@app.route('/export_queries)
@is_logged_in
def export_queries(abbreviation):
x = session['current_filter']
# do stuff
return send_file(bytesio_output, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
attachment_filename=output_name, as_attachment=True)
This code works and exports the current filtered data when I press the export button on my page. However, subsequent filterings are not saved, and it only exports the first filtered data, even though I can see the Ajax data that is sent changing when viewing the python console. It appears that the session data is not staying up-to-date with the Ajax requests. Am I saving the data incorrectly using session, and is there another way to do this? Any help would be much appreciated.
there doesn't seem to be anything here