博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

django cms 模版标签

Posted on 2018-02-24 10:57  bw_0927  阅读(535)  评论(0)    收藏  举报

http://docs.django-cms.org/en/develop/how_to/install.html

 

 

Templates

django CMS requires at least one template for its pages. The first template in the CMS_TEMPLATES list will be the project’s default template.

CMS_TEMPLATES = [
    ('home.html', 'Home page template'),
]

In the root of the project, create a templates directory, and in that, home.html, a minimal django CMS template:

{% load staticfiles cms_tags sekizai_tags %}
<html>
    <head>
        <title>{% page_attribute "page_title" %}</title>
        {% render_block "css" %}
    </head>
    <body>
        {% cms_toolbar %}
        {% placeholder "content" %}
        {% render_block "js" %}
    </body>
</html>

This is worth explaining in a little detail:

  • {% load cms_tags sekizai_tags %} loads the template tag libraries we use in the template.
  • {% page_attribute "page_title" %} extracts the page’s page_title attribute.  它是cms_tags的标签
  • {% render_block "css" %} and {% render_block "js" %} are Sekizai template tags that load blocks of HTML defined by Django applications.  js和css的占位符,其他继承自home.html的模版可以自定义各自的css和js源文件。  它是sekizai_tags的标签

     django CMS defines blocks for CSS and JavaScript, and requires these two tags.

     We recommended placing {% render_block "css" %} just before the </head> tag, and and {% render_block "js" %} tag just before the </body>.

  

 

  • {% placeholder "content" %} defines a placeholder, where plugins can be inserted.   placeholder是插件的占位符

  A template needs at least one {% placeholder %} template tag to be useful for django CMS. The name of the placeholder is simply a descriptive one, for your reference.

 

Django needs to be know where to look for its templates, so add templates to the TEMPLATES['DIRS'] list:

TEMPLATES = [
    {
        ...
        'DIRS': ['templates'],    #模版的路径
        ...
    },
]

 

Note

The way we have set up the template here is just for illustration.

In a real project, we’d recommend creating a base.html template, shared by all the applications in the project, that your django CMS templates can extend继承.

See Django’s template language documentation for more on how template inheritance works.

 

 

<link href="{% static "vendor/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet">  static标签来自staticfiles

 

  • 父模板

{% block content %}{% endblock content %}    --->定义

  • 子模板

{% block content %}                 --->指明覆盖父模板中的哪个块

子模板中的实现

{%endblock conetent%}

 

{% placeholder content or %}

如果没有定义placeholder的插件,则显示这行内容

{% endplaceholder %}

 

 

block用于继承,

placeholder用于插件替换,

上面的block和placeholder的名字都是content,没关系,因为 block是django的tag, placeholder是django-cms的tag

 

content重名没关系,因为block是django的标签;placeholder是django-cms的标签

==============

base.html模板:左右留有空白的页面,如下图

 

 

fullwidth.html 模板:全屏的模板,如下图: