Question

I'm getting the response from server that is escaped:

'item':'<b> Some Data </b>'

I pass such data to template useing item= json.loads(response)

By default django templates (in Google App Engine) escapes it further,
so its double escaped in results. I can use safe to remove one level of escaping like:

{{item|safe}}

How do i turn entities to their corresponding signs?

Was it helpful?

Solution 2

Warning - THIS IS NOT A RECOMMENDED SOLUTION. You should be using autoescaping instead (check Rafael's answer).

Following should do the job.
response.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>')

Update - After suggestion by Jan Schär, you should rather use the following : response.replace('&lt;', '<').replace('&gt;', '>').replace('&amp;', '&')

Because, if response is &amp;gt;, it would result in > instead of the correct &gt;. You should resolve &amp; in the last.

OTHER TIPS

You can do this:

{% autoescape off %}
  {{ your_text_var }}
{% endautoescape %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top