简体   繁体   中英

Jinja templating in javscript

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.

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) }}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM