我在undefined: msg以tmpl.Execute. 你应该如何在 Go 中检索 cookie?func contact(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { r.ParseForm() for k, v := range r.Form { fmt.Println("k:", k, "v:", v) } http.SetCookie(w, &http.Cookie{Name: "msg", Value: "Thanks"}) http.Redirect(w, r, "/contact/", http.StatusFound) } if msg, err := r.Cookie("msg"); err != nil { msg := "" } tmpl, _ := template.ParseFiles("templates/contact.tmpl") tmpl.Execute(w, map[string]string{"Msg": msg})}
1 回答
- 1 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消