gpt4 book ai didi

django - 是否可以在 django 模板中进行多级模板继承?

转载 作者:行者123 更新时间:2023-12-01 07:15:57 25 4
gpt4 key购买 nike

我有三个 html 文件:

  • base.html
  • page.html
  • 评论.html

  • page.html 我扩展 base.html .在 评论.html 我扩展 page.html .将 评论.html 延长 base.html 的积木?

    最佳答案

    是的,您实际上可以使用尽可能多的继承级别。来自 Django 书:

    One common way of using inheritance is the following three-level approach:

    (1) Create a base.html template that holds the main look-and-feel of your site. This is the stuff that rarely, if ever, changes.

    (2) Create a base_SECTION.html template for each “section” of your site. For example, base_photos.html, base_forum.html. These templatesall extend base.html and include section-specific styles/design.

    (3) Create individual templates for each type of page, such as a forum page or a photo gallery. These templates extend the appropriatesection template.


    更多信息: http://www.djangobook.com/en/2.0/chapter04.html

    关于django - 是否可以在 django 模板中进行多级模板继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6303548/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com