我希望你不要覺得我的問題很愚蠢,但我真的找不到答案。我正在嘗試提供我的 style.css 文件,但它不起作用。這是項目的結構: 在css文件中我有:“link href="style.css" rel="stylesheet" type="text/css"/"在 mainn.go 我正在嘗試使用以下方法提供 css 文件: router.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("/hpages")) ))任何幫助將不勝感激。謝謝!
1 回答

繁花不似錦
TA貢獻1851條經驗 獲得超4個贊
/hpages是絕對路徑。也許試試吧./hpages。
以下程序在我的本地機器上運行:
package main
import (
"log"
"net/http"
)
func main() {
router := http.NewServeMux()
router.Handle("/css/", http.StripPrefix("/css/",
http.FileServer(http.Dir("./hpages"))))
log.Fatal(http.ListenAndServe(":5000", router))
}
- 1 回答
- 0 關注
- 138 瀏覽
添加回答
舉報
0/150
提交
取消