亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

html / template中ParseFiles函數的不同行為

html / template中ParseFiles函數的不同行為

Go
繁星coding 2021-05-09 16:34:21
我不明白為什么的行為與func (t *Template) Parsefiles(...有所不同func ParseFiles(...。這兩個功能均來自“ html / template”包。package exampleimport (    "html/template"    "io/ioutil"    "testing")func MakeTemplate1(path string) *template.Template {    return template.Must(template.ParseFiles(path))}func MakeTemplate2(path string) *template.Template {    return template.Must(template.New("test").ParseFiles(path))}func TestExecute1(t *testing.T) {    tmpl := MakeTemplate1("template.html")    err := tmpl.Execute(ioutil.Discard, "content")    if err != nil {        t.Error(err)    }}func TestExecute2(t *testing.T) {    tmpl := MakeTemplate2("template.html")    err := tmpl.Execute(ioutil.Discard, "content")    if err != nil {        t.Error(err)    }}退出并顯示錯誤:--- FAIL: TestExecute2 (0.00 seconds)    parse_test.go:34: html/template:test: "test" is an incomplete or empty templateFAILexit status 1請注意,此方法TestExecute1通過得很好,所以這不是問題template.html。這里發生了什么?我想念MakeTemplate2什么?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 372 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號