If I have a box where people put comments, and then I display that comment like this…should I escape?
{{ c.title }}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Actually, it depends. Django’s templating engine does escaping automatically, so you don’t really need to escape.
If you add template filter “safe” like
{{c.title|safe}}then you do need to worry about things like html injection, because “safe” marks the string as such and it means that it won’t be escaped.There is also an {% autoescape on %}…{% endautoescape %} template tag, where “on” can be changed to “off”, if necessary. By default it’s on and the tag is not needed.
Other template engines may not be escaping by default, Jinja2 is one of them.