存儲在 PostgreSQL 中的數(shù)據(jù):The <b>Argentine Army</b> is. 數(shù)據(jù)類型:"content" text COLLATE "default".當通過 Golang 打印時,它變成 The <b>Argentine Army</b> is我需要從 PostgreSQL 打印精確數(shù)據(jù)而不轉(zhuǎn)義 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條經(jīng)驗 獲得超9個贊
這是由 html 模板引起的 - 您可以使用如下函數(shù):
func unsafe(x string) template.HTML {
return template.HTML(x)
}
獲取“未轉(zhuǎn)義”的 html。
- 1 回答
- 0 關注
- 165 瀏覽
添加回答
舉報
0/150
提交
取消