[Fixed]-Django. Jquery. escaping string with quotes error

25👍

Use escapejs filter.
Example:

{{ string|escapejs }}
👤Arti

1👍

Ok, I found a partial solution, hope it helps someone in the future. It is not an elegant solution, so, if anyone has a better option, it will be welcomed.

I included the text that has a “quoted” word inside a html hidden tag.

python-django:
text_with_quotes = 'this is a text and a word between "quotes"'

html:
<p id = "new_text" class = "hidden"> {{text_with_quotes|safe}}</p>

js:
new_text = $("#new_text").text();
$("#text_p").text(new_text);

it works. But there may be a better option using javascript and/or python.

Leave a comment