今天下载了一个iris包,做了一个小例子,想实现下面的功能: 输入网址http://localhost:8080,自动打开一个提前做好的index.html文件(在views文件下面)。
func main() { app := iris.New() app.Logger().SetLevel("debug") app.Use(recover.New()) app.Use(logger.New()) app.Handle("GET", "/", func(ctx iris.Context) { ctx.Redirect("./views/index.html") }) app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed)) }
可是views文件夹不知道放在什么位置?试了几个位置,打开http://localhost:8080之后, 网址变成http://localhost:8080/views/index.html,一直显示Not Found。
请大牛指点一下,谢谢!
有疑问加站长微信联系(非本文作者)

哪位大牛在线,麻烦指点一下吧
如果你想直接请求
/
时就返回index.html
的内容就需要添加一个模版(views)的目录,可以这样处理: