When django template renders parameters passed from views, it auto escapes characters that are considered as HTML entities.In English, that means characters like the double quote is convereted to
". This default behavior may not be what you want so it is important to know how to turn it off.
Here is a situation that I encountered while working on a project. I need to pull all of the
staffusers out of the database and then put their email addresses in the following format:
In the view function, I pull the email addresses out of the database and converted them into JSON format:
Then, in the template:
When I tested the page, this is what I see:
This happened because when python converts the
email_list to json, it added double quotes around the key and value pairs. When Django template renders it, it
auto escaped the double quote character (meaning convert it to #quot;). To stop Django from doing that:
The autoescape block controls whether the content inside of it should be auto escaped or not. So use it when you dont want to see those HTML entities.