Issue
I am using flask in order to deploy some variables to html and javascript:
prob_home_win = round(100 * prediction2[0,2],1)
prob_draw_game = round(100 * prediction2[0,1],1)
prob_away_win = round(100 * prediction2[0,0],1)
array_total = [prob_home_win, prob_draw_game, prob_away_win]
return render_template('index.html', array_total = array_total, user_image = full_filename)
then I read the variable with javascript:
var array_total = '{{ array_total }}';
but when I read it
console.log('array total =', array_total)
console.log('type of array_total =', typeof array_total)
it tells me that it is a string, which is not what I want, I want it to read it as an array... how can I make the variable to be read as an array?
Thanks in advance
Solution
This is because the variable is inside the quotation. But you can't remove the quotation, if you do, it will through syntax error.
You can use JSON.parse
array_total = JSON.parse('{{ array_total|tojson|safe }}')
Answered By - NavaneethaKrishnan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.