Golang Go语言中 pongo2 function 的问题

发布于 1周前 作者 vueper 来自 Go语言

Golang Go语言中 pongo2 function 的问题

html


                <div class="layui-form-item">
                    {{form_label("登陆绑定 IP" ,label_cls)}}
                    <div class="layui-input-inline" data-name="{{optionSessionBindIp.Name}}" data-value="optionSessionBindIp.Value">
                        {{switch_option_render(optionSessionBindIp, fn_format("/a/admin/setting/update?name=%s",option.Name) )}}

                    </div>
                </div><!-- 登录绑定 IP -->

fn_format 的代码


func GinContextExtend(c *gin.Context, dataList ...pongo2.Context) pongo2.Context {
	// 可以把获取当前用户放在这里
	d := pongo2.Context{
		"fn_format": fmt.Sprintf,
	}
	user, err := service.GinGetUser(c)
	if err == nil {
		d["user"] = user
		menuList, err := ReadMenuList(user.Role)
		if err != nil {
			panic(err)
		}
		menuListByte, err := json.Marshal(menuList)
		if err != nil {
			panic(err)
		}
		d["menuList"] = string(menuListByte)
	}
var newList = []pongo2.Context{
	d,
}
newList = append(newList, dataList...)

return ContextExtend(newList...)

}

现在运行报错


2021/06/20 15:18:05 [Recovery] 2021/06/20 - 15:18:05 panic recovered:
[Error (where: execution) in /home/vagrant/gcode/gadmin/templates/admin/setting.html | Line 26 Col 27 near 'switch_option_render'] [Error (where: execution) in /home/vagrant/gcode/gadmin/templates/admin/setting.html | Line 26 Col 69 near 'fn_format'] Calling a function using an invalid parameter
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:914 (0x9f703b)
        (*Context).Render: panic(err)
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:923 (0x9f70f8)
        (*Context).HTML: c.Render(code, instance)
/home/vagrant/gcode/gadmin/router/page_router/page_admin_setting.go:45 (0xb0c3d3)
        PageAdminSetting.func1: c.HTML(200, "admin/setting.html", render.GinContextExtend(c, pongo2.Context{
/home/vagrant/gcode/gadmin/router/page_router/page_admin_setting.go:54 (0xb0bcae)
        PageAdminSetting: }()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0xada3e6)
        (*Context).Next: c.handlers[c.index](c)
/home/vagrant/gcode/gadmin/pkg/middleware/middleware.go:73 (0xada3c5)
        LoginRequired.func1.1: c.Next()
/home/vagrant/gcode/gadmin/pkg/middleware/middleware.go:77 (0xadaa89)
        LoginRequired.func1: }()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0xa06f73)
        (*Context).Next: c.handlers[c.index](c)
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xa06f32)
        LoggerWithConfig.func1: c.Next()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0xa07e99)
        (*Context).Next: c.handlers[c.index](c)
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0xa07e80)
        CustomRecoveryWithWriter.func1: c.Next()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0xa06f73)
        (*Context).Next: c.handlers[c.index](c)
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xa06f32)
        LoggerWithConfig.func1: c.Next()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x9fd429)
        (*Context).Next: c.handlers[c.index](c)
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:489 (0x9fd40f)
        (*Engine).handleHTTPRequest: c.Next()
/home/vagrant/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x9fcefb)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2887 (0x7ac6c2)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1952 (0x7a7aec)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_amd64.s:1371 (0x46e800)
        goexit: BYTE    $0x90   // NOP

该怎么弄呀, 在 macro 里面不能调用 function?

py 转来 golang 好不习惯呀


更多关于Golang Go语言中 pongo2 function 的问题的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html

回到顶部