【发布时间】:2015-04-25 00:05:10
【问题描述】:
我正在使用路由器 (httprouter),并希望从根目录提供静态文件。
css 文件在
static/style.css
在模板中
<link href="./static/style.css" rel="stylesheet">
main.go
router := httprouter.New()
router.ServeFiles("/static/*filepath", http.Dir("/static/"))
router.GET("/", Index)
但是http://localhost:3001/static/style.css 给了我一个 404 错误,并且渲染页面中的样式也不起作用。
【问题讨论】:
-
省略“/static/”中的尾部斜杠?除此之外,您可以尝试将一些 Printfs 添加到路由器模块中以查看发生了什么。
标签: go