Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 785
phi Avatar asked Oct 23 '10 23:10

phi


People also ask

How do you encode a single quote in a URL?

Encode Your Apostrophe You can navigate to Web pages using several methods, such as clicking a bookmark or typing a URL into a browser's address bar. If the URL you need to type contains an apostrophe, replace the apostrophe with %27 and press "Enter" to navigate to the URL.

How do you escape a single quote?

Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.

How do I bypass a single quote in JavaScript?

We can use the backslash ( \ ) escape character to prevent JavaScript from interpreting a quote as the end of the string. The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.


2 Answers

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

like image 116
Daniel Roseman Avatar answered Oct 30 '22 11:10

Daniel Roseman


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 %}
like image 25
Yash Verma Avatar answered Oct 30 '22 12:10

Yash Verma