can't encode single quote (') using django's render_to_string
Asked Answered
J

2

8

i have a problem with django's render_to_string and encoding single quotes.

... = render_to_string('dummy.txt', {'request':request, 'text':text,}, context_instance=RequestContext(request)))

why are only these quotes translated to '#39;' and all other special characters not?

Jampacked answered 23/10, 2010 at 23:27 Comment(1)
Could you provide some input/ output? dummy.txt maynbe?Pteridology
D
12

Automatic escaping. Link now changed to https://code.djangoproject.com/wiki/AutoEscaping

Drews answered 24/10, 2010 at 8:1 Comment(1)
The "current" link in this answer links to the original proposal for the autoescape tag. Here's the link to the actual documentation... docs.djangoproject.com/en/4.0/ref/templates/builtins/…Bottle
B
1

To get your string in plain letters, you need to unescape it. surround your variable in autoescape off template tag. Something like this

{% autoescape off %}
{{ body }}
{% endautoescape %}
Bestir answered 8/7, 2020 at 13:55 Comment(2)
Yeah, this is what Daniel replied already 10 years ago. ;)Jampacked
Just in case if someone is looking for a quick copy paste solution. :-)Bestir

© 2022 - 2024 — McMap. All rights reserved.