dongyan5641 2016-07-18 20:53
浏览 42
已采纳

iris(Go web framework)iris.PongoEngine error from iris Official book

I started using Golang's Web Framework (Iris). I'm using the official iris book from gitbooks. I'm working on the last example in this page from the book. Following is the code used in the last example

./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"})
}

When I run the main.go, following are the errors I got.

# 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

I followed all the steps correctly, and also downloaded all the dependencies. I already took Learn How To Code: Google's Go (golang) Programming Language - Udemy and Golang Workshop by Caleb Doxcy, so I know the basics, like how to install dependencies, and how to import them etc. But the example shown in the book doesn't work.

  • 写回答

1条回答 默认 最新

  • douduan1953 2016-07-18 21:44
    关注
    import "github.com/kataras/iris"
    
    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.Run(iris.Addr(":8080"))
    }
    
    func hi(ctx iris.Context){
       ctx.ViewData("Name", "iris")
       ctx.View("hi.html")
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?