我正在使用jQuery mobile,我在一个html文件multipage.html
中有多个页面。我想从render
multipage.html
第2页传递一个可调用字典。有人可以建议我在Django中这样做吗?
答案 0 :(得分:0)
我在你的班级视图中猜到了你想要做的事情(因为基于函数的视图已被弃用):
class MyView(TemplateView):
template_name = "multipage.html"
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['pages_dict'] = [{'head' : 'foo', 'body' : 'bar' , 'foot' : 'smells'}, {'head' : 'foo2', 'body' : 'bar2' , 'foot' : 'smells2'}]
return context
然后在multipage.html
你可以:
{% for page in pages_dict %}
<div data-role="page">
{% for key, value in page.iteritems %}
<div data-role="{{key}}">
{{ value }}
</div>
</div>
{% endfor %}
这个例子适合你吗?如果没有,请向我澄清一下。