一: 模板语言之过滤器:
 " | " 前后的区分: 前面的是函数的第一个参数, 后面的是python的一个函数, 冒号后面的是第二个参数
例:  <p>过滤器之默认值:{{ ll | default:'没有值' }}</p>

def index(request):
     name = 'prince'  #字符串
     age = 20  #数字类型
     ll = [233, 290, 'bp', 'dsb']  #列表
     ll2 = []  #空列表
     tu = (1, 2, 3)  #元组
     dic = {'name': 'prince', 'age': 20, 'll': [1, 2, 3, 4]}
                
  # 在模板上相当于执行了test函数,打印了return的结果
  def test():
   print('prince')
   return 'bpcsmdj' 
                    
   # 类和对象
   class Person():  # Person 人
          def __init__(self, name, age):
               self.name = name
               self.age = age

       def get_name(self):
               return self.name  # 对象

         @classmethod
         def cls_test(cls):
              return 'cls'

         @classmethod
         def stetic_test(cls):
              return 'stetic'  #

         prince = Person('prince', 20)
         bastard = Person('bastard', 1000)

         Person_list = [prince, bastard]
         Person_dic = {'prince': prince, 'bastard': bastard}
                    
      # return render(request, 'index.html', {'name': name})
      # locals 会把index视图函数内(***全局变量是不可能的***)所有的变量当做参数传到index.html模版里面,打开连接时都能取到
      return render(request, 'index.html', locals())

1. length
  返回值的长度, 他对字符串和列表都起作用,  

 统计字符串长度:{{ name | length }}

 

 

 

二: 模板之标签

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2021-06-07
  • 2021-06-12
  • 2021-08-10
  • 2021-10-27
  • 2021-11-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-30
  • 2021-06-04
  • 2021-11-14
  • 2021-06-29
  • 2022-02-28
  • 2021-12-12
相关资源
相似解决方案