码迷,mamicode.com
首页 > 其他好文 > 详细

django之定义模板语法06(过滤器之多重过滤)

时间:2016-01-03 18:12:24      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

<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)

 

django之定义模板语法06(过滤器之多重过滤)

标签:

原文地址:http://www.cnblogs.com/dengyg200891/p/5096820.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!