I have a python-Django list:
list_a = ['user_a', 'user_b']
Now i render it to a template with the following code:
extra_context = {
'a': list_a
}
return direct_to_template(request, 'mytemplate.html', extra_context)
In my template, I wrote the following java script code to pass the list_a
Django-list to Js-list:
var user = [{% for i in user_list %}{{ i }}{% if forloop.last %}{%else%},{%endif%}{% endfor %}];
But when i open the template. It is showing following error (checked with Inspect element):
Uncaught ReferenceError : user_a is not defined
I tried to print the user
variable reside in javascript using Inspect Element
. It print the correct value i.e.
var user = [user_a, user_b]
I am not able to understand why is it happening :(
var user = [user_a, user_b]
, but what areuser_a
anduser_b
? Those inner names are not defined, hence the error. – kojiro Jul 7 '12 at 23:26