第二课学习的是模板变量,这节课是当内容繁多时需要把模板进行归置
从文件角度,可以在大文件夹下做小的文件夹,把HTML文件和view视图文件进行打包
路由文件内容不会过多
视图文件放如文件夹需要写init文件初始化
模板标签
if,for,foot(把HTML的body部分放在foot.html文件中),继承性child和parent
主要写在HTML文件body部分中
{% if a >= 90 %}
优秀
{% elif a >= 80 %}
良好
{% elif a >= 80 %}
良好
{% else %}
不及格
{% endif %}
{% for student in students %}
- title是子HTML的
- 学生名字是子HTML的,是可以传参的
- AI来自子HTML
{% include 'foot.html' %}
django中也可以做继承写,路由使用子HTML时,block里面使用子HTML的,外面继承父HTML的
”欢迎“和老师名字来自父HTML中没被继承的内容
视图文件就是render写HTML,因为要传输参数,加locals()
————————————————————————父HTML
{% block title %}
{% endblock %}
欢迎
{% block content1 %}
hello!!!!everybody!!!
{% endblock %}
{% block content2 %}
jicheng
{% endblock %}
老师名字,{{ teachers.name }}
————————————————————————————子HTML
————————————————————————————不需要外面的标签
{% extends "tab/parent.html" %}
{% block title %}
django
{% endblock %}
{% block content1 %}
{% for student in students %}
过滤器
视图文件中写字符串作为参数,需要传参
时间是现在的时间,所以再次刷新会发生变化
s="helloworld你好"
s1="byebyedjango"
t=datetime.datetime.now()
p=100
s2='he say"byebyedjango"'
模板过滤器
传递字符的长度:{{ s |length }}
传递字符的首字母:{{ s |first }}
字母大小写转换:{{ s |upper }}
字母小大写转换:{{ s |lower }}
首字母大写:{{ s |capfirst }}
首字母大写:{{ s |first |upper}}
首字母大写:{{ s1 |capfirst }}
首字母大写:{{ s1 |safe }}
现在时间:{{ t|date }}
现在时间:{{ t|date }}
传递数字加法{{ p|add:10 }}



