zoukankan      html  css  js  c++  java
  • 复习day03作业

    复习day03作业

    1. 在python实现链式调用操作

      class Beast(object):
          def __init__(self, name):
              self.name = name
      
          def foo(self):
              print(self.name)
              return self
      
          @property
          def hello(self):
              print('你好骚年!')
              return self
      
          @staticmethod
          def hah(obj_name):
              print(f'o(* ̄︶ ̄*)o,{obj_name}')
      
      
      b = Beast('lxx')
      b.foo().hello.hah('hello world!')
      
      """
      lxx
      你好骚年!
      o(* ̄︶ ̄*)o,hello world!
      """
      
    2. 关键字过滤的标签

      # 创建自定义标签的步骤
      
      step 1:在app中创建templatetags文件夹
      step 2:在templatetags文件夹下创建任意的.py文件,如my_tag.py
      step 3:在my_tag.py文件中写入以下的两句话
          from django import template
          
          register = template.Library()
      
      step 4:书写自定义的标签
          
      @register.simple_tag()
      def filter_keyword_tag(msg):
          filter_keyword_list = [
              'cnm',
              '草泥马',
              'fuck',
              'mzd',
              'xjp',
          ]
          for item in filter_keyword_list:
              if item in msg:
                  msg = msg.replace(item, '***')
          return msg
      
      step 5:自定义标签的使用
      {% load my_tag %}
      {% filter_keyword_tag msg %}
      

      views.py

      def test(request):
          msg = 'cnm12345草泥马网页uueurmzd5757577蒋介石dhdhhdxjp'
          return render(request, 'test.html', locals())
      

    3. 常用(非常用)字段和参数,Django-model进阶https://www.cnblogs.com/liuqingzheng/p/9506212.html)

      pass
      
  • 相关阅读:
    SharePoint Designer
    SharePoint Tricks
    树型dp(2019/1/19学习笔记) by csy
    2019/2/21测试(noip2015提高组day2
    loj刷题记录2019/2/20
    2019/2/16测试
    splay(水题)
    noip2016提高组day2
    2019/2/13测试(noip2016提高组day1原题)
    洛谷p1083借教室
  • 原文地址:https://www.cnblogs.com/surpass123/p/13225926.html
Copyright © 2011-2022 走看看