【发布时间】:2016-10-12 16:49:19
【问题描述】:
我在使用 go lang 创建的 Web 应用程序中添加一些 CSS 时遇到问题。 main.go 和 html 文件包含在根目录中,style.css 包含在 root/css 目录中
我的 .*go 代码是
package main
import (
"html/template"
"net/http"
)
func main(){
http.HandleFunc("/home", mainViewHandler)
http.ListenAndServe(":8080", nil)
}
func mainViewHandler(responseWriter http.ResponseWriter,request *http.Request){
t, _ := template.ParseFiles("main.html")
t.Execute(responseWriter, 0)
}
而html代码是
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="todo/style.css">
<meta charset="UTF-8">
<title>Main Page</title>
</head>
<body>
<h2>Take your choice</h2>
<a href="/edit">Edit</a>
<a href="/add">Add</a>
<a href="/list">List</a>
</body>
</html>
【问题讨论】:
标签: css web-applications go