gpt4 book ai didi

ubuntu - iris (Go web framework) iris.PongoEngine error from iris 官方书

转载 作者:IT王子 更新时间:2023-10-29 02:13:41 26 4
gpt4 key购买 nike

我开始使用 Golang 的 Web 框架 (Iris)。我正在使用来自 gitbooks 的官方 iris 书。我正在研究 last example in this page从书中。以下是上一个例子中使用的代码

./templates/hi.html

<!-- ./templates/hi.html -->
<html><head> <title> Hi Iris [THE TITLE] </title> </head>
<body>
<h1> Hi {{ Name }}
</body>
</html>

./main.go

// ./main.go
import (
"github.com/kataras/iris"
)

func main() {
iris.Config.Render.Template.Engine = iris.PongoEngine
iris.Get("/hi", hi)
iris.Listen(":8080")
}

func hi(ctx *iris.Context){
ctx.Render("hi.html", map[string]interface{}{"Name": "iris"})
}

当我运行 main.go 时,出现以下错误。

# command-line-arguments
./main.go:8: iris.Config.Render undefined (type *config.Iris has no field or method Render)
./main.go:8: undefined: iris.PongoEngine

我正确地遵循了所有步骤,并且还下载了所有依赖项。我已经拍了Learn How To Code: Google's Go (golang) Programming Language - UdemyGolang Workshop by Caleb Doxcy ,所以我知道基础知识,比如如何安装依赖项,以及如何导入它们等。但是书中显示的示例不起作用。

最佳答案

import "github.com/kataras/iris/v12"

func main() {

app := iris.New()
app.RegisterView(iris.Django("./templates", ".html")) // <-----

// RESOURCE: http://127.0.0.1:8080/hi
// METHOD: "GET"
app.Get("/hi", hi)

app.Listen(":8080")
}

func hi(ctx iris.Context){
ctx.ViewData("Name", "iris")
ctx.View("hi.html")
}

关于ubuntu - iris (Go web framework) iris.PongoEngine error from iris 官方书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445818/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com