【问题标题】:Go: unable to render external stylesheetsGo:无法渲染外部样式表
【发布时间】:2014-10-22 10:51:14
【问题描述】:

我正在尝试渲染外部样式表。我不确定为什么这不起作用:

去:

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

【问题讨论】:

    标签: go


    【解决方案1】:

    您的文件服务器位于/layout/,所以应该是

    <link rel="stylesheet" type="text/css" href="/layout/stylesheets/home.css" />
    

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 2017-08-04
      • 1970-01-01
      相关资源
      最近更新 更多