cms模版抽离

新建一个cms_base.html文件作为基础模板,把cms_index.html的内容拷贝到cms_base.html中。

编辑 cms_base.html,把在不同页面会变动的部分用block包起来

标题部分

<title>{% block title %}{% endblock %}</title>

在head中再预留一个block个,因为在其他页面可能会再加载一些js或css

{% block head %}{% endblock %}

内容标题和内容

<h1>{% block page_title %}{% endblock %}</h1>
<div class="main_content">
      {% block main_content %}{% endblock %}
</div>

模板已经编辑好了,现在就可以来编辑cms_index.html了

把cms_index.html的原来内容清空,然后继承cms_base.html,在把block填进来填充自己的内容就可以了,如下

{% extends 'cms/cms_base.html' %}

{% block title %}
    CMS管理系统
{% endblock %}

{% block  page_title %}
    欢迎来到CMS管理系统
{% endblock %}


<!--因为首页这里没有其他内容,这里就不配置main_content了-->
cms_index.html

相关文章:

  • 2021-08-03
  • 2021-07-25
  • 2022-12-23
  • 2021-08-26
  • 2022-03-03
  • 2021-08-12
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2022-01-10
  • 2022-01-25
  • 2021-10-21
  • 2021-10-01
  • 2021-08-29
相关资源
相似解决方案