为什么parseFiles总是报错 以下为代码 及报错
```go
func login(w http.ResponseWriter,r *http.Request) {
fmt.Println("method",r.Method)//看是get还是post
if r.Method == "GET" {
t,_ := template.ParseFiles("login.html")
log.Println(t.Execute(w,nil))
} else {
r.ParseForm()
fmt.Println("username",r.Form["username"])
fmt.Println("password",r.Form["password"])
}
}
```
错误信息
```
2018/03/18 22:32:42 http: panic serving [::1]:51132: runtime error: invalid memory address or nil pointer dereference
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc042058dc0)
D:/Go/src/net/http/server.go:1726 +0x122
panic(0x8329e0, 0xa5eb50)
D:/Go/src/runtime/panic.go:505 +0x258
html/template.(*Template).escape(0x0, 0x0, 0x0)
D:/Go/src/html/template/template.go:95 +0x49
html/template.(*Template).Execute(0x0, 0x8ca900, 0xc04215c000, 0x852fe0, 0xc0421381b0, 0x0, 0x0)
D:/Go/src/html/template/template.go:119 +0x41
main.login(0x8cd3c0, 0xc04215c000, 0xc042144000)
D:/go_workspace/webProject/src/main.go:37 +0x369
net/http.HandlerFunc.ServeHTTP(0x8acd50, 0x8cd3c0, 0xc04215c000, 0xc042144000)
D:/Go/src/net/http/server.go:1947 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa6d8c0, 0x8cd3c0, 0xc04215c000, 0xc042144000)
D:/Go/src/net/http/server.go:2337 +0x1aa
net/http.serverHandler.ServeHTTP(0xc042064dd0, 0x8cd3c0, 0xc04215c000, 0xc042144000)
D:/Go/src/net/http/server.go:2694 +0x1eb
net/http.(*conn).serve(0xc042058dc0, 0x8cd580, 0xc0420160c0)
D:/Go/src/net/http/server.go:1830 +0x11f9
created by net/http.(*Server).Serve
D:/Go/src/net/http/server.go:2795 +0x6eb
2018/03/18 22:32:42 http: panic serving [::1]:51133: runtime error: invalid memory address or nil pointer dereference
goroutine 19 [running]:
net/http.(*conn).serve.func1(0xc042058e60)
D:/Go/src/net/http/server.go:1726 +0x122
panic(0x8329e0, 0xa5eb50)
D:/Go/src/runtime/panic.go:505 +0x258
html/template.(*Template).escape(0x0, 0x0, 0x0)
D:/Go/src/html/template/template.go:95 +0x49
html/template.(*Template).Execute(0x0, 0x8ca900, 0xc04215c0e0, 0x852fe0, 0xc0421382a0, 0x0, 0x0)
D:/Go/src/html/template/template.go:119 +0x41
main.login(0x8cd3c0, 0xc04215c0e0, 0xc042146000)
D:/go_workspace/webProject/src/main.go:37 +0x369
net/http.HandlerFunc.ServeHTTP(0x8acd50, 0x8cd3c0, 0xc04215c0e0, 0xc042146000)
D:/Go/src/net/http/server.go:1947 +0x4b
net/http.(*ServeMux).ServeHTTP(0xa6d8c0, 0x8cd3c0, 0xc04215c0e0, 0xc042146000)
D:/Go/src/net/http/server.go:2337 +0x1aa
net/http.serverHandler.ServeHTTP(0xc042064dd0, 0x8cd3c0, 0xc04215c0e0, 0xc042146000)
D:/Go/src/net/http/server.go:2694 +0x1eb
net/http.(*conn).serve(0xc042058e60, 0x8cd580, 0xc04213a040)
D:/Go/src/net/http/server.go:1830 +0x11f9
created by net/http.(*Server).Serve
D:/Go/src/net/http/server.go:2795 +0x6eb
```
有疑问加站长微信联系(非本文作者)