英文:
Go: unable to render external stylesheets
问题
我正在尝试渲染外部样式表,但不确定为什么不起作用:
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" />
有什么问题吗?我按照这里的示例进行操作:https://stackoverflow.com/questions/13302020/rendering-css-in-a-go-web-application
英文:
I'm trying to render external stylesheets. I'm not sure why this is not working:
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)
}
Dir structure:
gocode
layout
stylesheets
home.css
home.html
main.go
HTML:
<link rel="stylesheet" type="text/css" href="/stylesheets/home.css" />
Whats wrong? I followed the example here: https://stackoverflow.com/questions/13302020/rendering-css-in-a-go-web-application
答案1
得分: 3
您的文件服务器位于/layout/
,因此应该是
<link rel="stylesheet" type="text/css" href="/layout/stylesheets/home.css" />
英文:
Your file server is at /layout/
, so it should be
<link rel="stylesheet" type="text/css" href="/layout/stylesheets/home.css" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论