HTML Escape of Django Basics:

Source: Internet
Author: User

HTML escape
    • Django automatically HTML-escapes the string, such as the following values in the template:
视图代码:def index(request):    return render(request, ‘temtest/index2.html‘,                  {                      ‘t1‘: ‘
    • Display effects such as:

Characters that will be automatically escaped
    • HTML escape, which is the output of the included HTML tags, is not interpreted, because when the user submits the string, it may contain some offensive code, such as JS script
    • Django automatically escapes the following characters:
< 会转换为&lt;> 会转换为&gt;‘ (单引号) 会转换为&#39;" (双引号)会转换为 &quot;& 会转换为 &amp;
    • Use escape filter When displaying untrusted variables, generally omitted because Django automatically escapes
{{t1|escape}}
Turn off escape
    • Use safe filters for variables
{{ data|safe }}
    • Use Autoescape tags for code blocks
{ % autoescape off %}{{ body }}{ % endautoescape %}
    • Label Autoescape accept on or off parameters
    • The auto-escape label is closed in the base template and is also closed in the child template
String literals
    • Manual escape
{ { data|default:"<b>123</b>" }}
    • should be written as
{ { data|default:"&lt;b&gt;123&lt;/b&gt;" }}

HTML Escape of Django Basics:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.