Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using Flask, and I am trying to send data to my html page. The obvious choice is Jinja templating: {{ input_msg }}, but the problem is I need I am inside curly brackets already, since I need to put the variable into javscript:

request.onload = function() {
if (request.status === 200 && request.responseText === 'done') {
    window.location = {{ inp_msg }};
}
};

The above will not work because curley brackets are being used for templating, but inside javscript as well. Is there another way to send data, not jinja? If not, is there another jinja way?

Thanks in advance.

question from:https://stackoverflow.com/questions/65546348/jinja-templating-in-javscript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
241 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to pass a string for window.location.

window.location = '{{ inp_msg }}'

Also use can use url_for function.

window.location = '{{ url_for(func_name) }}'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...