我最近学习了Golang,并尝试创建一个以Go为后端的网站。我用一个名为Martini的框架正确地完成了这个任务,但是我想不使用框架。
有人能告诉我html和tmpl的区别吗?因为我想调用一个用DB行加载表的页面,我想,首先我必须理解其中的区别。
这就是我试过的:
server.go:
package main
import (
"io/ioutil"
"net/http"
"html/template"
)
func main(){
http.HandleFunc("/index/"), viewIndex)
http.ListenAndServe(":8080", nil)
}
func viewIndex(w http.ResponseWriter, r *http.Request){
t, _ := template.ParseFiles("index.html")
}我不知道结构是什么,但我将index.html放在:/templates/index.html上:
包含Hello World
提前谢谢你。
发布于 2014-07-08 09:22:40
没有。调用文件index.html或index.tmpl取决于作者。我个人更喜欢.tmpl,因为这些文件包含的不仅仅是HTML。
一些特定的包(如马提尼渲染)可能只用于某些文件扩展名,但几乎所有的包都应该是可配置的。
如果你刚开始,我建议你读http://jan.newmarch.name/golang/template/chapter-template.html
https://stackoverflow.com/questions/24626093
复制相似问题