【问题标题】:How to render two or more templates?如何渲染两个或多个模板?
【发布时间】:2015-11-26 10:02:18
【问题描述】:

我有两个模板要在我的 django 项目中呈现: 这是模板'b.html'

<html>
<body>
{% include 'a.html' %}
     {{ userName}}
</body>
</html>

它是“a.html”:

     {{ another_name}}

我正在完成任务并将userName返回到'b.html'和another_name到'a.html',我该怎么办?应该使用render_to_response?谢谢~

【问题讨论】:

    标签: django-templates


    【解决方案1】:

    您可以查看include 标签的文档:https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#include

    您可以使用render_to_response() 来渲染您的模板:

    return render_to_response('b.html', {
         'userName': 'a',
         'another_name': 'b'
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多