verbatim 标签在DTL中是用于解析特殊字符串的,如需让其按照原来的显示,可用verbatim标签将其解析关闭
views.py 代码
1 from django.shortcuts import render,HttpResponse,redirect,reverse 2 3 def index(request): 4 context = { 5 'info':'<a href="http://www.baidu.com">百度</a>' 6 } 7 return render(request, 'index.html', context=context)
index.html 代码
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>模板渲染</title> 6 </head> 7 <body> 8 {% verbatim %} 9 {{ info }} 10 {% endverbatim %} 11 </body> 12 </html>
浏览器显示