Django块标签if else 配合not and or的使用
来源:互联网 发布:淘宝怎么添加宝贝分类 编辑:程序博客网 时间:2024/06/05 04:10
Django块标签if else 配合not and or的使用
模板文件index1.html中的代码如下:
<html lang="en"> <head> <meta charset="UTF-8"> <title>wuranghao</title> </head> <body> <h1>hello:{{user.name}}</h1> <h1>age:{{user.age}}</h1> <h1>male:{{user.sex}}</h1> {% if user.age > 18 %} <li>未成年</li> {% endif %} {% if not user2 %} <li>user2是不存在的</li> {% endif %} {% if not user.name %} <li>user.name是为空的</li> {% endif %} {% if not user2 or not user.name %} <li>user2是不存在的或者是user.name是为空的</li> {% endif %} </body></html>
views.py中的代码如下:
# Create your views here.from django.http import HttpResponsefrom django.template import loader,Contextclass Person(object): def __init__(self,name,age,sex): self.name=name self.age=age self.sex=sex def getName(self): return "my name is "+self.namedef index1(request): t=loader.get_template("index1.html") person=Person("wuranghao",19,"male") c=Context({"user":person}) return HttpResponse(t.render(c))
运行结果如下:
0 0
- Django块标签if else 配合not and or的使用
- struts2 标签 date & if else 的使用
- Struts2标签 if else 的使用
- 简单标签的if和 if-else使用代码
- if and if or的使用
- C标签的if else
- if else的使用
- if-else的使用
- struts2中iterator标签的嵌套使用(if/else)
- struts2中iterator标签的嵌套使用(if/else)
- Struts 2中if else iterator property标签的使用 .
- JSTL中类似if else的标签使用例子
- 如何实现JSTL if else if else 的jsp标签
- if or else
- 利用python and or,if else 简化代码
- if/else的使用心得
- jstl的if...else使用
- if else语句的使用
- 向文件中写入字符串及多个变量小结
- altium designer里把贴片元器件放在底层该如何去设置操作?
- svn数据库自动发布程序
- 面试笔试经验-java重载、重写及数据库索引
- 蓝懿ios 技术内容交流和学习心得 11.14
- Django块标签if else 配合not and or的使用
- 500G JAVA视频网盘分享 (Jeecg社区)
- 冰天雪地一
- 从一个fork()实例理解全缓冲与行缓冲
- Win7 Flask
- K—means算法实现流程
- C-#与##
- [Leetcode]Simplify Path
- android 中this与supe的区别