1、index页面修改: <html> <head> <title>DOcument</title> </head> <body> <h1>{{user}}</h1> </br> </br> <h1>过滤器</h1> {% for book in user %} <li>{{book | upper |lower | capfirst}}</li> {% empty %} <li>没有找到书籍</li> {% endfor %} <h1>过滤器-时间操作</h1> <p>{{today}}</p> <p>{{today | date:‘Y-m-d‘}}</p> </body> </html>
2、views.py文件
# -*- coding: cp936 -*- from django.http import HttpResponse from django.template import loader,Context import datetimedef index(request): t=loader.get_template(‘index.html‘) bookList=[‘python‘,‘C++‘,‘java‘,‘php‘] #时间过滤操作 today=datetime.datetime.now() #向html页面传递数据 c=Context({‘user‘:bookList,‘today‘:today}) #渲染方法 t=t.render(c) return HttpResponse(t)
时间: 2024-11-07 03:43:19