1、HTML模板引用靜態目錄
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2、模板繼承
------------定義模板------------
//layout.html
{% load static %}
<!DOCTYPE html>
........
<body>
<div>
{% block content%}
//需要填充的內容
{% endblock %}
.......
</body>
</html>
------------繼承模板------------
//list.html
{% extends 'layout.html' %}
{% block content %}
//填充的內容
{% endblock %}
3、datatime類型
Python語法取值:
obj.create_time.strftime("%Y-%m-%d")
Django 模板語法取值:
obj.create_time|date:"Y-m-d"
4、choices
如果定義了choices對應關係,想直接取對應數據內容
Python語法取值:
#原始數據:
obj.gender
#取數據內容:
obj.get_gender_display( )
Django 模板語法取值:
5、ForeignKey關聯取值問題
Python語法取值:
#取值,取到的是編號
obj.depart_id
#取關聯的真實內容
obj.depart.title
Django 模板語法取值:
#取關聯的真實內容
obj.depart.title