in views:
'some_array': ['text1','text2', 'text3']
When I try to transfer it in template to js script:
<script type="text/javascript">
some_func({{ some_array }});
</script>
In source code it looks like:
<script type="text/javascript">
some_func([u'text1', u'text2', u'text3']);
</script>
So it is an error in javascript.
How to remove prefix u'' from array’s elements or how to get around this?
Thanks!
When you transfer a Python list into a string, you are creating the Python representation of your variable (
__repr__). What you are trying to do here is create a JavaScript representation of the same data.JSON is a great way to transfer data because so many languages have good JSON parsers. In the case of JavaScript this is even more true since JSON is actually native JavaScript syntax so you can put the JSON representation straight into the JavaScript source.
To generate the JSON, you can use Python’s built-in JSON library (Python 2.6+).
This creates a string that can be used in your template.