I use Python pystache (which is the standard api utility).
Here is an example of my data structure:
{
"results": [
{
"user": "foo",
"flags": [
"a",
"b",
"c"
]
},
{ ... }
]
}
Now in my template I am trying to do this:
{{
{{> stuff}}
{{/results}}
Where stuffis partial and partial looks like this:
user: {{ user }}
isX: {{ flags.x }}
Now what provides the data to the template is a class that acts as a “presentation model”, so I can normalize some data and have a template that interacts with normalized data, and not with the json source data shown above.
The problem is that I don’t know how to implement my view model to work with the fact that we iterate over nested data.
, flags, , , true false, , x.
:
class Feed(Presenter):
def prepare_view(self, **params):
self.view = View()
self.view.template_path = '/app/static/views/feed.mustache'
self.view.results = self.post.results
self.view.flags = namedtuple('_', ['x'])('true')
return self
, namedtuple , x, true false
, namedtuple, , .
- ?