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?

phi
  • 333
  • 5
  • 9

2 Answers2

12

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

Sriram Mahavadi
  • 417
  • 4
  • 8
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • The "current" link in this answer links to the original proposal for the autoescape tag. Here's the link to the actual documentation... https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#autoescape – GlenVaughan Apr 07 '22 at 15:39
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 %}
DHamrick
  • 8,338
  • 9
  • 45
  • 62
Yash Verma
  • 461
  • 5
  • 4