You need to use quotes: var v = '{{=variable}}';
After the template is processed, it will look like: var v = 'HOLA'; Anthony On Wednesday, January 28, 2015 at 6:04:23 PM UTC-5, José Eloy wrote: > > Hello! > > How can I pass a python string to javascript? I know how to pass an > integer variable to javascript. > > Example: > > def pass_variable(): > variable = 25 > return dict(variable=variable) > > In the view: > <script type="text/javascript"> > var v={{=variable}}; > console.log(v); > </script> > > If I pass a integer variable, javascript receive it well, but if I pass a > string, javascript doesn't recognize it. > > Now, let's assume that we use variable = "HOLA" > > I get the error: (using Firefox console) > --------------------------------------------------- > ReferenceError: HOLA is not defined > var v = HOLA; > --------------------------------------------------- > What am I doing wrong? > > Regards. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.