zoukankan      html  css  js  c++  java
  • 026:if标签使用详解

    if标签使用详解:

    if 标签: if 标签相当于 Python 中的 if 语句,有 elif 和 else 相对应,但是所有的标签都需要用标签符号  {%  %}  进行包裹。 if 标签中可以使用 ==、!=、<、<=、>、>=、in、notin、is、is not 等判断运算符。示例代码如下:

    一、views.py文件:

    def index(request):
        return render(request, 'index.html', context={'age': 20})

    二、index.html模板文件:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    {% if age < 18 %}
        <p>您是未成年人</p>
    {% elif age >= 18 and age < 80 %}
        <p>您是成年人</p>
    {% else %}
        <p>您是老年人</p>
    {% endif %}
    
    </body>
    </html>
  • 相关阅读:
    jdbc代码
    openwrt vsftp
    openwrt 配置samba && ubuntu 配置samba
    如何学习开源项目
    Makefile 笔记
    Samba 学习笔记
    quilt-补丁工具
    to-do-list
    新增feeds模块
    linux命令
  • 原文地址:https://www.cnblogs.com/zheng-weimin/p/10164781.html
Copyright © 2011-2022 走看看