gpt4 book ai didi

Django 相当于 Rails application.html.erb?

转载 作者:行者123 更新时间:2023-12-04 17:21:37 25 4
gpt4 key购买 nike

Django 中是否有类似于 Rails application.html.erb 的 HTML 文件共享“主”布局?如果没有,是否有关于如何创建一个的最佳实践?

最佳答案

在 Django 中,最佳实践是使用三级模板使用 template inheritance .

我引用 django book向您解释:

You can use as many levels of inheritance as needed. 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 (e.g., base_photos.html and base_forum.html). These templates 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 appropriate section template.

This approach maximizes code reuse and makes it easy to add items to shared areas, such as section-wide navigation.

关于Django 相当于 Rails application.html.erb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259581/

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