ERROR:html/template: ".../index.html" is undefined

There will be a error with loading template files as your guidance!
Maybe my error code.
This commit is contained in:
Shuai Qi 2017-04-12 10:43:22 +08:00 committed by GitHub
parent e2212d40c6
commit 40af9ad6fc

View File

@ -495,14 +495,15 @@ Using templates with same name in different directories
```go ```go
func main() { func main() {
router := gin.Default() router := gin.Default()
router.LoadHTMLGlob("templates/**/*") router.LoadHTMLGlob("templates/posts/*")
router.GET("/posts/index", func(c *gin.Context) { router.GET("/posts/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Posts", "title": "Posts",
}) })
}) })
router.LoadHTMLGlob("templates/users/*")
router.GET("/users/index", func(c *gin.Context) { router.GET("/users/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "users/index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Users", "title": "Users",
}) })
}) })