dsnnvpobaljihv3490 2018-06-29 10:18
浏览 110

golang虹膜直接返回模板html

<!-- file: web/views/hello/index.html -->
<html>
<head>
    <title>{{.Title}} - My App</title>
</head>
<body>
    <p>{{.MyMessage}}</p>
</body>
</html>

package main

import (
  "github.com/kataras/iris"
)
func main() {
    app := iris.New()
    // Load the template files.
    app.RegisterView(iris.HTML("./web/views", ".html"))
    // Serve our controllers.
    mvc.New(app.Party("/hello")).Handle(new(controllers.HelloController))
    // http://localhost:8080/hello
    app.Run(
        iris.Addr("localhost:8080"),
        iris.WithoutVersionChecker,
        iris.WithoutServerError(iris.ErrServerClosed),
        iris.WithOptimizations,
    )
}

package controllers

import (
    "github.com/kataras/iris/mvc"
)
type HelloController struct{}

var helloView = mvc.View{
    Name: "hello/index.html",
    Data: map[string]interface{}{
        "Title":     "Hello Page",
        //"MyMessage": "Welcome to my awesome website",
    },
}
func (c *HelloController) Get() mvc.Result {
    return helloView
}

I want to direct return template html. in func (c *HelloController) Get() mvc.View { return helloView } , but Once I do this , The parameters in the template will be empty. {{.Title}} and {{.MyMessage}} is missing

  • 写回答

1条回答 默认 最新

  • doushan5222 2018-07-05 20:58
    关注

    here are my results from the mvc/overview example, as expected: enter image description here

    Can I help you with something?

    评论

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了