我试图让一个处理程序在每次从提交按钮获取数据时更新一行, 这是我的代码:
func RowHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != "POST" {
http.ServeFile(res, req, "homepage.html")
return
}
Person_id := req.FormValue("Person_id")
stmt, err := db.Prepare("update Cityes set Status='right' where Person_id=?")
if err != nil {
log.Print("error ", err)
}
_, err = stmt.Exec(&Person_id)
t, err := template.ParseFiles("city_update.html") //hier i just want to show a text in html Page
if err != nil {
log.Fatal(err)
}
err = t.Execute(res, "/city_update")
}
最佳答案
在这里而不是跟随
err = t.Execute(res, "/city_update")
将用于填充模板的数据作为发送参数发送到 Execute
而不是字符串。 link to doc
例如.
err = t.Execute(res,struct{ID string}{Person_id})
关于golang : can't execute t. 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45410176/