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 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误