zoukankan      html  css  js  c++  java
  • The Definitive Guide To Django 2 学习笔记(五) 第四章 模板 (一)基本模板系统

    引入模板系统的原因,view中引入硬编码并非明智的选择,设计上的任何改变都会需要改动代码。python代码和HTML代码应该分开,这是多数Web站点的共识,分开会提高效率。

    基本模板系统

    Django模板是一串用来分离数据与文档模型的文本。参考下面的模板:

    <html>
    <head><title>Ordering notice</title></head>
    <body>
    <h1>Ordering notice</h1>
    <p>Dear {{ person_name }},</p>
    <p>Thanks for placing an order from {{ company }}. It's scheduled to
    ship on {{ ship_date|date:"F j, Y" }}.</p>
    <p>Here are the items you've ordered:</p>
    <ul>
    {% for item in item_list %}
    <li>{{ item }}</li>
    {% endfor %}
    </ul>
    {% if ordered_warranty %}
    <p>Your warranty information will be included in the packaging.</p>
    {% else %}
    <p>You didn't order a warranty, so you're on your own when
    the products inevitably stop working.</p>
    {% endif %}
    <p>Sincerely,<br />{{ company }}</p>
    </body>
    </html>

    1.被双括号包围的是变量

    2.被打括号和百分号包围的 称为 模板标签,实际上是判断逻辑

    3.最后,在第二段中包含一个过滤器的例子,{{ship_date|date:"F j,Y"}}, 我们把ship_date 传给date过滤器,参数为F j,Y.此过滤器将时间格式化成一个给定的格式,过滤器用|来加载。

  • 相关阅读:
    咱家自己的vim配置
    Oauth2手册 第一章
    tcpdf 将网页生成pdf
    Lua 学习记事本
    Lua中的table函数(转)
    Lua常用函数
    将显示对象变成黑白
    Flash 3D 基础
    高等物理:数值积分
    Camera类的基本使用
  • 原文地址:https://www.cnblogs.com/kfx2007/p/3425582.html
Copyright © 2011-2022 走看看