【发布时间】:2013-06-14 05:24:21
【问题描述】:
通过 shadynasty.biz/blog/2012/07/30/quick-and-clean-in-go 链接,我正在尝试在 Go 编程中创建模板。我的项目结构是使用 Go-SDK 谷歌应用引擎创建的。 google_appengine/myapp/hello/hello.go 文件存在,那么在哪里创建模板文件夹?我在 "hello" 文件夹中创建了 "template" 文件夹,但出现错误 "panic: open templates/base.html: The system cannot find the path specified" 并且服务器停止运行。可以做什么?
【问题讨论】:
-
例如: package main import( "fmt" "net/http" "html/template" ) var index = template.Must(template.ParseFiles( "/templates/base.html", " /templates/index.html", )) func handler(w http.ResponseWriter, r *http.Request) { if err := index.Execute(w, nil); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } fmt.Fprint(w, "hello", "\n") } func init() { http.HandleFunc("/" , 处理程序) }
标签: google-app-engine go