<html> <head> <title>DOcument</title> </head> <body> <h1>{{user}}</h1> </br> </br> <h1>过滤器</h1> <p>1、运用到了Linux管道思想</p> <p>2、先将book的值变为大写,再转化为小写,再转化为首字母大写</p> {% for book in user %} <li>{{book | upper |lower | capfirst}}</li> {% empty %} <li>没有找到书籍</li> {% endfor %} </body> </html>
# -*- coding: cp936 -*- from django.http import HttpResponse from django.template import loader,Context class Person(): def __init__(self,name,age,sex): self.name=name self.age=age self.sex=sex def say(self): return ‘My name is ‘+self.name def index(request): t=loader.get_template(‘index.html‘) person=Person(‘deng‘,17,‘female‘) bookList=[‘python‘,‘C++‘,‘java‘,‘php‘] #bookList=[] Dict={‘age‘:25, ‘yuyan‘:‘python‘, ‘where‘:‘china‘, ‘name‘:‘xiaodeng‘, ‘sex‘:‘male‘} #向html页面传递数据 c=Context({‘user‘:bookList}) #渲染方法 t=t.render(c) return HttpResponse(t)
时间: 2024-12-29 13:30:31