我正在尝试渲染外部样式表。我不确定为什么这不起作用:
GO:
func main() {
http.HandleFunc("/", homeHandler)
http.HandleFunc("/image/", imageHandler)
http.Handle("/layout/", http.StripPrefix("/layout/", http.FileServer(http.Dir("layout"))))
http.ListenAndServe(":8000", nil)
}
目录结构:
gocode
layout
stylesheets
home.css
home.html
main.go
HTML:
<link rel="stylesheet" type="text/css" href="/stylesheets/home.css" />
什么错了?我按照这里的示例:Rendering CSS in a Go Web Application
答案 0 :(得分:3)
您的文件服务器位于/layout/
,因此应该是
<link rel="stylesheet" type="text/css" href="/layout/stylesheets/home.css" />