转到模板包括外部CSS

时间:2015-06-28 10:34:45

标签: go go-templates

index.go

package main
import (
    "html/template"
    "net/http"
)
func viewHandler(w http.ResponseWriter, r *http.Request) {
    t, _ := template.ParseFiles("index.html")
    t.Execute(w, nil)
}
func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
    http.HandleFunc("/index", viewHandler)
    http.ListenAndServe(":8080", nil)
}

在我的index.html中,我使用了以下路径

<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.css">

.css的路径如下,

幅(文件夹)

| --- index.go

| ---静态/ CSS / xxx.css

但是,CSS不包含在html中。如何更改代码以解决此问题

1 个答案:

答案 0 :(得分:0)

由于端口冲突,未正确包含CSS文件。感谢@Intermernet。 :)