基本信息Go 版本:go1.4.2 darwin/amd64操作系統:Mac OS X 10.10.5我正在開發一個基于go和gin編寫的小型 Web 項目。這是我的 golang 代碼。運行后,go run test.go我們有一個 Web 服務器,它正在偵聽 8089。Golang test.gopackage mainimport "github.com/gin-gonic/gin"import "net/http"func main() { router := gin.Default() router.LoadHTMLGlob("templates/*") router.GET("/index", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", gin.H{ "scheme": "http", "domain": "meican.loc", }) }) router.Run(":8089") // listen and serve on 0.0.0.0:8089}后端生成的 html 代碼應包含前端 javascript 引擎(假設為 Angular.js)使用的模板。所以模板代碼在script標簽中,就像這樣:模板/index.html 的一部分<script type="text/template" charset="utf-8"> <div data="{{.scheme}}://{{.domain}}/qr"></div> <div data="{{.scheme}}://{{.domain}}/qr"></div> <!-- problem here --></script>當{{.domain}}第二次使用時,我得到了不同的結果。我刷新了瀏覽器并查看了源代碼。然后我得到了這個:瀏覽器源碼結果<script type="text/template" charset="utf-8"> <div data="http://meican.loc/qr"></div> <div data="http://"meican.loc"/qr"></div> <!-- problems here --></script>第二個div有 2 個額外的雙引號。為什么會發生這種情況?以及如何解決這個問題?
- 1 回答
- 0 關注
- 186 瀏覽
添加回答
舉報
0/150
提交
取消