I have a page with a ton of input boxes (numbers, checkboxes etc.), I need to prepare the data before the POST request. So I have a bunch of methods that make adjustments to the names of these inputs, bundle them up nicely in one object called: data
. For my purposes, putting the submit button in the above form does not work, because the POST request is done with the default names. For that reason all the above inputs are enclosed in a div, and then I have a submit button and onClick I am doing an axios POST request:
axios({
method: 'post',
url: '/smart-beta/',
data
});
On the Flask end I have this:
elif request.method == "POST":
sbe_args = json.loads(request.data)
sb = SbeGenerator(sbe_args)
sb.run() # TODO: depending on how long this takes, may add a loading animation to the page
eg = ExcelGenerator(sb)
eg.create_excel()
beta = sb.beta
sharpe = sb.sharpe
annualised_return = sb.ann_mean
annualised_vol = sb.ann_vol
time_series = sb.port_json
stocks = sb.last_stocks_json
print("Time series: " + str(time_series))
print("stocks: " + str(stocks))
# TODO: Do the redirect here (getting 302 status on the POST request if redirect is here, becasue
# TODO: axios catches it in then
print("Rendering template")
return render_template('smart_beta/calculation.html')
I get the 200 on the POST request, but it never renders my other page. It just hangs on the current page. Is that because the axios's promise is never resolved? when I do .then(function(response) {console.log(response);});
<- it still hangs. The reason I need to use render_template is because I need to pass stuff like time_series into that page.
EDIT: When I navigate to the response of the POST request in the dev tools on the web page, I can see that it is the page that I need.