首页 > 其他 > 详细

第二十五节 autoescape标签

时间:2020-03-09 13:46:30      阅读:67      评论:0      收藏:0      [点我收藏+]

autoescape 标签可以用于转义,当从视图函数传入的字符串是一个标准的HTML语句时,出于保护机制,django会把它只当成一个字符串在页面直接显示,而不是作为HTML语句生效,如需使其生效,可用autoescape 将其关闭

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     {% autoescape off %}
 9         {{ info }}
10     {% endautoescape off %}
11 </body>
12 </html>

 

第二十五节 autoescape标签

原文:https://www.cnblogs.com/kogmaw/p/12447787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!