【问题标题】:django generic view send context to multiple templates at the same timedjango 通用视图同时将上下文发送到多个模板
【发布时间】:2018-10-06 05:19:18
【问题描述】:

在这种情况下,我尝试将列表视图上下文 (book_list) 同时发送到多个模板。

我尝试通过这样做来编辑模板名称:

class BookListView(ListView):
    model = Book
    def get_template_names(self):
        template_name=["catalog/index.html","catalog/book_list.html"]
        return template_name

但是 book_list 仍然只有 catalog/book_list.html 知道而不是 catalog/index.html(所以我添加的函数没有做任何事情)。

有什么建议吗?

最好的问候

【问题讨论】:

    标签: django django-generic-views


    【解决方案1】:

    你不能 :) 每个视图负责一个 url 和一个模板将呈现。实际上,我什至找不到并举例说明何时需要做您想做的事情。

    我认为你必须阅读template inheritance

    【讨论】:

    • 感谢您的回复...我是这么认为的,但我一直在试图绕过它。感谢您确认这是不可能的。
    猜你喜欢
    • 2020-03-24
    • 2012-01-30
    • 2012-06-08
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多