I am working on a single page Flask application in python. To change the content of the page, I simply call a javascript function that hides one div and reveals another.
One of these divs contains a form where a user may upload a file, which I run through a python script that parses data from the file.
The problem is that after executing the code, Flask seems to want me to redirect to a new page. I would prefer to return a trigger to simply run my javascript function.
The HTML form:
<form class='upload-form' id='upload-form' action="/upload" method='POST' enctype="multipart/form-data" onsubmit="return show_and_hide('load', 'upload')">
<input type="file" name='file' value="Browse...">
<input type="submit" value='Upload'>
</form>
The Javascript function:
var callFunction;
function show_and_hide(div_in, div_out){
var shower = document.getElementById(div_in);
var hider = document.getElementById(div_out);
var hider_items = hider.children;
var i;
for(i = 0; i < hider_items.length; i++){
hider_items[i].style.animation = "hide 1s";
}
callFunction = setTimeout(change_div, 1000, div_in, div_out);
var shower_items = shower.children;
var n;
for(n = 0; n < shower_items.length; n++){
shower_items[n].style.animation = "show 1s";
}
return true;
}
And the flask application (I do not actually have it returning ???):
@app.route('/upload', methods=['POST', 'GET'])
def upload_file():
f = request.files['file']
new_file_name = str(uuid.uuid1()) + '.zip'
f.save(os.path.join('uploads/', new_file_name))
path = 'uploads/' + new_file_name
return ???
I appreciate any advice! Thank you!