golang : can't execute t. 执行

标签 go

我试图让一个处理程序在每次从提交按钮获取数据时更新一行, 这是我的代码:

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/

相关文章:

正则表达式在不同分隔符之间进行匹配

go - 如何在Golang中将GMT日期转换为UNIX时间?

go - slice 是按值传递的吗?

javascript - 从/到 Javascript 字符串从 Go int64/uint64 序列化反序列化

go - 使用 time.Unix() 从 float 解析带小数的 unix 时间戳?

go - 如何在golang中对定长数组进行排序?

variables - 在 Golang 中,我们可以为变量名声明一些字符串值吗?

javascript - 在将数据推送到模板时使链接可点击

dictionary - Go 的底层 map

parsing - 以 Go 为目标匹配 ANTLR4 中任何可打印的类字母字符