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
<!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<script>alert("前路昭然你我共进")</script> </br>
不执行:2
<script>alert("前路昭然你我共进")</script>
</br>
</div>
</body>
</html>