如何在django中从多页html渲染页面

时间:2013-11-20 05:11:33

标签: django jquery-mobile django-templates django-views

我正在使用jQuery mobile,我在一个html文件multipage.html中有多个页面。我想从render multipage.html第2页传递一个可调用字典。有人可以建议我在Django中这样做吗?

1 个答案:

答案 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 %}

这个例子适合你吗?如果没有,请向我澄清一下。