I have a dictionary in a HTML file. I want to be able to download this data in the 'xlsx' (Excel) format. I have the code to convert any Python dictionary into a newly converted Excel file but I don't know how to pass the dictionary from the HTML to the Python/Flask route method.
Asked
Active
Viewed 180 times
-1
-
you really can't ... you should use js to generate a json from what data you have set in html ... call a url (which is you python / flask server) – StefanMZ Sep 14 '20 at 21:56
1 Answers
1
Flask Route to get data.
@app.route('/postmethod', methods = ['POST'])
def get_post_javascript_data():
jsdata = request.get_json() # parse as json
AJAX to send JSON data
var person = {"name":"Andrew", "loves":"Open Source"};
var asJSON = JSON.stringify(person);
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/postmethod", true);
xhttp.setRequestHeader("Content-type", "application/json; charset=utf-8");
xhttp.send(asJSON);

fatalcoder524
- 1,428
- 1
- 7
- 16