HTML输出
===
简单的:
~~~
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/*") // 目录 下不能有其他文件夹 不会会报错
//router.LoadHTMLFiles("templates/template1.html", "templates/template2.html")
router.GET("/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{
"Title": "Main website",
})
})
router.Run(":8080")
}
~~~
多级:
~~~
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
app := gin.Default()
app.LoadHTMLGlob("temp/**/*")
app.GET("/home", func(c *gin.Context) {
c.HTML(http.StatusOK,"posts/index.html",gin.H{
"Title":"Jell",
})
})
app.Run(":8085")
}
~~~
感觉这个也太麻烦了把!
~~~
{{ define "posts/index.html"}}
{{.Title}}
{{ end }}
~~~
最后
以上就是坚定萝莉最近收集整理的关于gin路由打开html页面,HTML · Gin框架入门到入土 · 看云的全部内容,更多相关gin路由打开html页面,HTML内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复