#index页面代码: <html> <head> <title>DOcument</title> </head> <body> <h1>{{user}}</h1> </br> </br> <h1>过滤器</h1> <p>{{ string | truncatewords:‘2‘ }}</p> //显示前2个字(非字母) </body> </html> ######views文件 # -*- coding: cp936 -*- from django.http import HttpResponse from django.template import loader,Context import datetime #向html页面传递数据 c=Context({‘string‘:‘my name is xiaodeng‘}) //显示结果为: my name ... #渲染方法 t=t.render(c) return HttpResponse(t)
django之定义模板语法08({{ string | truncatewords:'2' }})
时间: 2024-08-25 07:47:30