复习day03作业
-
在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! """
-
关键字过滤的标签
# 创建自定义标签的步骤 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())
-
常用(非常用)字段和参数,Django-model进阶(https://www.cnblogs.com/liuqingzheng/p/9506212.html)
pass