我正在尝试从文件夹@objc
加载模板@objc public class myClass {
@objc var str: String = "str"
}
。尝试在Firefox浏览器中查看时,它会加载空白。
handler.go 文件
page.gohtml
cmd / main.go 文件
cms/template
templates / page.gohtml
var Tmpl = template.Must(template.ParseGlob("../templates/*"))
func ServeIndex(w http.ResponseWriter, r *http.Request) {
p := &Page{
Title: "Go Projects CMS",
Content: "Welcome to the Home Page!",
Posts: []*Post{
{
Title: "Hello World!",
Content: "Hey y'all, Thanks for coming",
DatePublished: time.Now(),
},
{
Title: "This Has Comments",
Content: "Atlassian Just Bought Trello...GO!",
DatePublished: time.Now().Add(-time.Hour),
Comments: []*Comment{
{
Author: "Davy Jones",
Content: "This is something to say about something",
DatePublished: time.Now().Add(-time.Hour / 2),
},
},
},
},
}
Tmpl.ExecuteTemplate(w, "page", p)
}
答案 0 :(得分:0)
我使用错误处理时发现了问题。
if err := Tmpl.ExecuteTemplate(w, "page", p); err != nil {
log.Printf("Template error: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
我在 comment.gohtml
中使用defined "comment"
时打印了“没有此类模板注释”
很抱歉发布这个问题,我最近启动了GoLang。