Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何在Go中从html模板访问Redis结果_Templates_Go_Redis - Fatal编程技术网

Templates 如何在Go中从html模板访问Redis结果

Templates 如何在Go中从html模板访问Redis结果,templates,go,redis,Templates,Go,Redis,我有这个功能 func front(w http.ResponseWriter, r *http.Request) { posts, _ := client.HGet("post:1", "title") tmpl.ExecuteTemplate(w, "index", posts) } 日志println显示确实有结果 2014/06/04 21:44:23 [title test_title content this is a test content] 但是我不能让它显示在“索

我有这个功能

func front(w http.ResponseWriter, r *http.Request) {
  posts, _ := client.HGet("post:1", "title")
  tmpl.ExecuteTemplate(w, "index", posts)
}
日志println显示确实有结果

2014/06/04 21:44:23 [title test_title content this is a test content]
但是我不能让它显示在“索引”模板上

“索引”模板如下所示

{{define "index"}}
<p>{{.Posts}}</p>
{{end}}
{{定义“索引”}
{{.Posts}

{{end}
我的问题是{.Posts}没有显示任何内容。但它应该显示类似于
test\u title content的内容这是一个测试内容

我想要的是从html模板访问Redis结果

你知道怎么做吗?

试着从模板中删除Posts变量,如下所示:

{{define "index"}}
<p>{{.}}</p>
{{end}}
{{定义“索引”}
{{}}

{{end}

这应该行得通。Post似乎不是go文件中“posts”变量的成员。

可能重复您为什么重新发布该问题?@fabrizioM抱歉,我本来打算删除另一个并重新发布一个更好的解释,但在此过程中我的电脑关闭了。。现在更容易理解了吗?我无法编辑这篇文章,因为它被一些网络问题阻塞了,但我使用的是gosexy redis,但是任何redis客户端都是受欢迎的,如果它能让生活更轻松的话