django-标签中的过滤器

django-标签的应用

官网链接
django-标签中的过滤器

views

def test_filter(request):
    dic={}
    dic['str']='sssqwqeqw'
    dic['int']=100
    dic['html']='<script>alert("前路昭然你我共进")</script>'
    return  render(request,'test_filter.html',dic)

test_filter.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test_filter</title>
</head>
<body>
    <p>{{str|upper}}</p>
    <p>{{int|add:'8'}}</p>
    <div>
        已执行:
        {{html|safe}} </br>

        不执行:
        1{{html}} </br>

        
        不执行:2
        {% autoescape on %}
        {{html }}
        {% endautoescape %}
        </br>
    </div>
</body>
</html>

显示html
django-标签中的过滤器


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test_filter</title>
</head>
<body>
    <p>SSSQWQEQW</p>
    <p>108</p>
    <div>
        已执行:
        <script>alert("前路昭然你我共进")</script> </br>

        不执行:
        1&lt;script&gt;alert(&quot;前路昭然你我共进&quot;)&lt;/script&gt; </br>

        
        不执行:2
        
        &lt;script&gt;alert(&quot;前路昭然你我共进&quot;)&lt;/script&gt;
        
        </br>
    </div>
</body>
</html>
上一篇:多线程数据读取


下一篇:关于SPARK的 与周边比较