1. 導入time模塊
import time
2. 獲取現在時間,使用"年-月-日 時:分:秒"這樣的模板,賦值給變量
在views.py中:
pt = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
3.寫入數據庫
details.objects.create(time=pt)
4.在頁面上渲染
在views.py中:
return render(request,'index.html',{'details':details})
在index.html中:
{% for i in details %} <tr> <td>{{ i.id }}</td> <td>{{ i.response_partment }}</td> <td>{{ i.project_manager }}</td> <td>{{ i.client_name }}</td> <td>{{ i.price }}</td> <td>{{ i.time|date:"Y-m-d H:i:s" }}</td>//"年-月-日 時:分:秒" <td>{{ i.time|date:"Y-m-d" }}</td>//"年-月-日" <td>{{ i.status }}</td> </tr> {% endfor %}