I have a python list that contains a list of strings. Those strings contain HTML and JavaScript. Right now, I am using sentences = json.dumps(l) in Django view, then in the template I use {{sentences|safe}}, it works for some strings, but it breaks on the strings that contain lots of HTML and JavaScript. How do I fix this problem?
Thank you for your help.
I tried JSON.parse(sentences), {{sentences|escapejs}}, {{escape|safe}}
# in django view
sentences = json.dumps(l)
return render(request, 'detail.html', {
'sentences': sentences
})
// in template, attempt to pass the jsonified python list to js array
var random = {{sentences|safe}};
SyntaxError: "" literal not terminated before end of script 73:78:35396
SyntaxError: unexpected token: identifier
73:78:12
SyntaxError: unexpected token: identifier
73:78:4
SyntaxError: unexpected token: identifier
73:78:20
SyntaxError: unexpected token: identifier
73:78:20