10

Go 的 html/template 把我的模板自动给转码了

 1 year ago
source link: https://www.v2ex.com/t/850741
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Go 编程语言

Go 的 html/template 把我的模板自动给转码了

  godlovesxcjtest · 5 小时 11 分钟前 · 782 次点击

模板代码如下:

{{- define "common/web/atom"}}
<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">

    </feed>
{{end}}

很简单的一个代码,主要是想用来实现一个 atom 服务器,返回浏览器 atom.xml 文件

但是调用 ExecuteTemplate 方法后,变成了这个样子:



<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
     
    </feed>

尖括号"<" 变成了 <

很奇怪的一个问题。我知道 Go 的 html/template 会对一些输入进行转码,避免把用户的输入生成到 html 。

但是为什么会把我的模板里面的也进行转码了呢


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK