Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

My Blog

从此烟雨落金城,一人撑伞两人行。

Gin访问静态文件和模板文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main
import (
"github.com/gin-gonic/gin"
)
func gologin(c *gin.Context){
c.HTML(200, "login.html", nil)
}
func login(c *gin.Context){
username := c.PostForm("username")
password := c.PostForm("password")
c.HTML(200, "index.html", gin.H{
"username": username,
"password": password,
})
}
func main(){
e := gin.Default()
e.Static("/assets", "./assets")
e.LoadHTMLGlob("tempates/*")
e.GET("/login", gologin)
e.POST("/login", login)
e.Run()
}

e.Static("/assets", "./assets")读取css和js等静态文件
e.LoadHTMLGlob("tempates/*")读取html等模板文件

评论