여기 앱의 Example입니다.Golang GAE - 콧수염 구조체의 intID
Google Appengine의 Golang에 약간의 블로그 시스템을 구축하고 Mustache를 템플릿 엔진으로 사용하려고 시도 중입니다. 필수 코드는 다음 위치에 있습니다 : golang-code/handler/handler.go 그래서, GAE 자동 intID (INT64)를 할당
datastore.Put(c, datastore.NewIncompleteKey(c, "Blogposts", nil), &blogposts)
통해
type Blogposts struct {
PostTitle string
PostPreview string
Content string
Creator string
Date time.Time
}
데이터는 GAE에 전달된다
은 그래서, 구조체를 갖는다. 는 이제 최신 블로그 게시물
// Get the latest blogposts
c := appengine.NewContext(r)
q := datastore.NewQuery("Blogposts").Order("-Date").Limit(10)
var blogposts []Blogposts
_, err := q.GetAll(c, &blogposts)
모든 것이 잘가 작동 할 때까지
을 얻기 위해 노력했다,하지만 난 intID에 액세스하려고 할 때 (또는 stringID를, 무엇이든) 나는이 :-(<h3><a href="/blog/read/{{{intID}}}">{{{PostTitle}}}</a></h3>
에 대한 액세스를 필요 없다 ?
(PostTitle이 intID, 나는 사물의 수천을 해봤하지, 작품, 아무것도 :-(일하지)
누구나 생각이 좋은 것
편집 :! 나는 콧수염을 사용합니다. 코드에서
내가 사용x["Blogposts"] = blogposts
data := mustache.RenderFile("templates/about.mustache", x)
sendData(w, data) // Equivalent to fmt.Fprintf
그리고 데이터와 .mustache 템플릿에 액세스 할 수 있습니다
{{{내용}}} 또는 {{{PostTitle}}}
'{{{}}}': html/템플릿을 확장하고 있습니까? 그렇다면 최소한 코드 조각을 추가하여 살펴보십시오. – zzzz
안녕하세요, 아니요, 저는 콧수염을 사용합니다. 편집을 참조하십시오 :-) – Testuser