doumo1807831 2018-02-11 06:33
浏览 104
已采纳

如何在IRIS中禁用自动转义

I insert HTML tags into database table:

<table>
<tr>
   <td>1</td>
   <td>2</td>
   <td>3</td>
</tr>
</table>

And send retrieved data into View

func MyEvent(ctx iris.Context){
        rows := ...
        ctx.ViewData("rows", rows[0])
        ctx.View("template.html")
}

How could I disable auto escaping just in this event?

  • 写回答

1条回答 默认 最新

  • donglu1881 2018-02-11 21:26
    关注

    How you would get raw HTML through the template and into the output would depend on which template engine you're using with Iris. Iris supports five template engines out-of-the-box:

    If you're using the standard html/template package then you'd mark the string as "safe HTML" using the template.HTML type:

    ctx.ViewData("rows", template.HTML(rows[0]))
    

    or add your own filter which just does a return template.HTML(s) and use that inside the template.

    If you were using Handlebars then you'd use {{{...}}} in the template or raymond.SafeString in a helper:

    {{{yourHTML}}}
    

    If you're using one of the other template engines then you'd use whatever mechanism they offer for getting raw HTML through the template.

    All of this assumes, of course, that you're scrubbing and sanitizing the HTML before it gets into the database or before it gets from the database to the template.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?