dongye7231 2015-03-24 07:06
浏览 38
已采纳

没有引用CSS文件

I have this code as my myApp.go:

package fastaticapp

import (
 "html/template"
 "log"
 "net/http"
)

func init() {
http.HandleFunc("/", rootHandler)
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))

if r.URL.Path != "/" {
    errorHandler(w, r, http.StatusNotFound, "")
    return
}

page := template.Must(template.ParseFiles(
    "static/_base.html",
    "static/index.html",
))

if err := page.Execute(w, nil); err != nil {
    errorHandler(w, r, http.StatusInternalServerError, err.Error())
    return
}

}

And the direcotry Layout looks like this:

webapp/
  myApp/
    server.go
  static/
    index.html
    _base.html
    img/
    css/
     main.css

I am using template package with Must function. running the dev server, the HTML page gets rendered by the browser and using developer tools I can see the html contents. The problem is main.css file within the css folder does not appear to be properly handled by the server. Any thought on this would be highly appreciated.

  • 写回答

1条回答 默认 最新

  • dpl9717 2015-03-24 08:10
    关注

    Use

    http.Dir("static/css")
    

    instead of

    http.Dir("css")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去
    • ¥15 关于unity开发steamvr程序遇到的问题
    • ¥60 求tc downloader的下载方式
    • ¥15 华为 快捷方式 手电筒 接口
    • ¥15 Qt6.5支不支持Android13开发啊
    • ¥20 网络只能跑一半,应该如何设置
    • ¥20 Python调用百度开发者平台人脸识别接口