0

On my server the array appears as follows:

data = [u'Data1', u'Data2', u'Data3']

In Django, I send the data through to the client using:

render(..., {'data': data})

On the client side I try to render in JavaScript using:

{{data}}

and get:

[u'Data1B', u'Data2', u'Data3']

How can I fix this encoding issue?

2 Answers 2

2

You need to safe escape the string inorder to work fine

{{data|safe|escape}}
Sign up to request clarification or add additional context in comments.

Comments

0

You can also pass your data as a json object. In your view.py

from django.utils import simplejson
...
render(...{'data':simplejson.dumps(data)})

and then in your javascript function

var data = JSON.parse({{data}}) 

But as @karthikr already said, |safe is your case absolutely sufficient.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.