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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题