Go模板包含外部css

Go模板包含外部css,go,go-templates,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.StripP

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

|---static/css/xxx.css


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

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

“不包含在html中”是什么意思?根据代码,服务器应该在
serveraddress.com/static/CSS/bootstrap.CSS
下提供CSS文件,而不是包含在任何内容中。我很确定你在这里写的文件名是错的。“索引,开始”?@Staven抱歉,那是main.go。实际上,当我点击时,它告诉我404错误。我如何修复它?@Wyatt我刚刚测试了你的代码,它在我的机器上正确地提供了CSS文件。你确定你的机器上的8080端口没有冲突吗?@Intermernet非常感谢。我把它改成8090,这个问题就解决了