golang输出模板
发布时间:2020-12-16 09:26:32 所属栏目:大数据 来源:网络整理
导读:如何显示模板的内容? 包主 import ( "fmt" "html/template" "os")func main() { t := template.New("another") t,e:=t.ParseFiles("test.html") if(e!=nil){ fmt.Println(e); } t.Execute(os.Stdout,nil)} 为什么不呢? test.html存在 解决方法 您不需要使
如何显示模板的内容?
包主 import ( "fmt" "html/template" "os" ) func main() { t := template.New("another") t,e:=t.ParseFiles("test.html") if(e!=nil){ fmt.Println(e); } t.Execute(os.Stdout,nil) } 为什么不呢? 解决方法
您不需要使用New创建新模板,然后在其上使用ParseFiles.还有一个ParseFiles函数,它负责在幕后创建一个新模板.这是一个例子:
package main import ( "fmt" "html/template" "os" ) func main() { t,err := template.ParseFiles("test.html") if err != nil { fmt.Println(err); } t.Execute(os.Stdout,nil) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |