存儲在 PostgreSQL 中的數據:The <b>Argentine Army</b> is. 數據類型:"content" text COLLATE "default".當通過 Golang 打印時,它變成 The <b>Argentine Army</b> is我需要從 PostgreSQL 打印精確數據而不轉義 HTML 標簽。我不確定這是 Go 還是 PostgreSQL 問題。下面是我的 Golang 代碼:package mainimport ( "database/sql" "github.com/labstack/echo" _ "github.com/lib/pq" "html/template" "io" "log" "net/http")// type Gallery struct here// type Template struct & function herefunc main() { e := echo.New() // DB connection here // Parse template & render here e.Get("/", func(c *echo.Context) error { rows, err := db.Query("SELECT uri, title, content FROM gallery WHERE id=123") // Handle error here gallery := []Gallery{} for rows.Next() { b := Gallery{} err := rows.Scan(&b.Uri, &b.Title, &b.Content) // Handle error here gallery = append(gallery, b) } return c.Render(http.StatusOK, "onlytestingtpl", gallery[0]) }) e.Run(":4444")}
1 回答

富國滬深
TA貢獻1790條經驗 獲得超9個贊
這是由 html 模板引起的 - 您可以使用如下函數:
func unsafe(x string) template.HTML {
return template.HTML(x)
}
獲取“未轉義”的 html。
- 1 回答
- 0 關注
- 166 瀏覽
添加回答
舉報
0/150
提交
取消