Builder, decorator like early knowledge Review

Recap
1, iterables, iterators, generators, decorators What is the difference?
  Iterables: internal __iter__ method implements, it is an iterator
  iterator: internal and implements __iter__ __next__ method may be performed for loop
  generator: yield There is an internal function generator, the generator also a __next__ method, which is essentially an iterator.
  Generator has two functions: 1, generation 2, iterator
  decorators: before or after execution function to execute an extended functional capabilities, decoration is achieved with closures
2, object-oriented approach? Object-oriented three ways:
  Example Method: def func (self): pass the object to call the method with
  the class method: CLS is the class name of the current operation
      @classmethod
      DEF FUNC (CLS): Pass
  static method:
      @staticmethod
      DEF FUNC (): pass
  the difference between classes and static methods:
    class methods: the traditional method of a class parameter cls
    static method: static method parameters do not pass
    the same point: can be used to call a method of the class
3, class there are two fields:
    a static field
    dynamic field
    class A:
      S = "AAA" static field
      the __init __ DEF (Self):
        the self.name object field name =
4 properties:

Copy the code
the @Property
 DEF FUNC (Self):
  Pass 
@ fee.setter 
DEF Fee (Self):
  Pass 

@ fee.deltter 
DEF Fee (Self):
  Pass 
it as a method to invoke the property 
because the property can not be modified, you can use @ fee.setter
Copy the code

5, there is any way to improve query related to database performance?
  Indexed way: the index is to speed up query: filter out the final results you want by constantly narrowing the scope of data
  index is divided into several categories?
  Index Category    1. Ordinary index index: Find the acceleration     2. index unique       primary key index: primary key: Find + acceleration constraint (not null and only)       unique index: unique: Find + acceleration constraint (unique)     3. joint index       -primary key (id, name): the primary key index       -unique (id, name): United unique index       -index (id, name): joint general index     4. the full-text index fulltext: searching for a very long article, the effect of the most it is good.     The spatial index spatial: understanding enough, almost no 6, how to hit the index?   Create an index, did not hit   hit: the equivalent of precise queries. . . in, like not hit   sorted index, the field must also select an index field, or can not hit 6, django lifecycle   request First wsgi --- --- If the authentication middleware went through routing system - - view function (taken from the database to the data, rendering the template) 7, what middleware done?   User login   rights management   crsf
 




















  the session
8, the routing system in the url must remember to add a starting terminator
9, view: request request have got what?
  request.POST POST data which might not get, but the body will get the data
  request.body
  request.GET
  request.path_info
  request.method
  request.session
  Request.Cookies
  ....
10, Form validation
  create a rule:
  class :
    field:    

        required=True,
        min_length=3,
        max_length=18,
        error_messages={
            'required': '密码不能为空',
            'min_length': '密码长度不能小于3',             'max_length': '密码长度不能大于18',             'invalid': '密码格式错误',         },

      validators=[RegexValidator('\d+','只能是数字') ]
11、数据库操作
  13个API操作
    all,filter,get,values,values_list,fast,last,distinct,reverse,include,order_by, exist,count
    另加2个:only、refer
    FK ManyToMany
12、模板
  自定义过滤器和标签
  1、常见一个templatetags文件夹
  2、在该文件夹中随便创建一个py文件
  3、在使用自定义simple_tag和filter的html文件中导入之前创建的 my_tags.py
  3、{% load my_tags %} 
  自定义过滤器函数的参数只能两个,可以进行逻辑判断
  自定义标签无参数限制,不能进行逻辑判断

13. Session和Cookie是什么?什么区别和关系?Session原理?
由于http无状态,当请求进来的时候不会保存状态,当每次访问的时候就不知道是谁进来了,这就引出了cookie
cookie的原理:
  服务器产生内容,浏览器收到请求后保存在浏览器;
  当浏览器再次访问时,浏览器会自动带上cookie,
  这样服务器就能通过cookie的内容来判断这个是“谁”了。
session 的原理:
  session会保存在服务器,这样比较安全
总结而言:cookie弥补了http无状态的不足,让服务器知道来的人是“谁”;
       但是cookie以文本的形式保存在本地,自身安全性较差;
     所以我们就通过cookie识别不同的用户,对应的在session里保存私密的信息以及超过4096字节的文本。

另外,上述所说的cookie和session其实是共通性的东西,不限于语言和框架
14. 什么是模板继承,好处是什么?

  模板继承{% extends  "base.html" %}

   好处:缩减代码


内容回顾
1、可迭代对象、迭代器、生成器、装饰器有什么区别?
  可迭代对象:内部实现了__iter__方法,是一个迭代器
  迭代器:内部实现了__iter__和__next__方法,可以进行for循环
  生成器:函数内部有yield的就是生成器,生成器也有一个__next__方法,它的本质是一个迭代器。
  生成器有两大功能:1、生成 2、迭代
  装饰器:在函数执行之前或者函数执行之后要扩展的功能,装饰器是用闭包实现的
2、面向对象的方法?面向对象有三种方法:
  实例方法:def func(self):pass 用对象去调用方法
  类方法:cls是当前操作的类名
      @classmethod
      def func(cls):pass
  静态方法:
      @staticmethod
      def func():pass
  类方法和静态方法的区别:
    类方法:类方法传一个cls参数
    静态方法:静态方法不用传参数
    相同点:都可以用用类去调用方法
3、类里面的字段有两种:
    静态字段
    动态字段
    class A:
      s ="aaa" 静态字段
      def __init__(self):
        self.name = name 对象字段
4、属性:

Copy the code
@property
def func(self):
  pass
@fee.setter 
def fee(self):
  pass

@fee.deltter
def fee(self):
  pass
吧一个方法当做属性来调用
因为属性不能被修改,可以用@fee.setter 
Copy the code

5、提高查询数据库性能相关的有什么方式?
  加索引的方式:索引就是加速查询 :通过不断的缩小数据的范围筛选出最终想要的结果
  索引又分为几大类?
  索引分类
    1.普通索引index :加速查找
    2.唯一索引
      主键索引:primary key :加速查找+约束(不为空且唯一)
      唯一索引:unique:加速查找+约束 (唯一)
    3.联合索引
      -primary key(id,name):联合主键索引
      -unique(id,name):联合唯一索引
      -index(id,name):联合普通索引
    4.全文索引fulltext :用于搜索很长一篇文章的时候,效果最好。
    5.空间索引spatial :了解就好,几乎不用
6、如何命中索引?
  创建索引,未命中
  命中:相当于精确查询。。。in,like就不命中
  排序条件为索引,则select字段必须也是索引字段,否则无法命中

6、django的生命周期
  请求先到wsgi---中间件---如果验证通过就走到路由系统----视图函数(从数据库中取到数据,在模板中渲染)
7、中间件做过什么?
  用户登录
  权限管理
  crsf
  session
8、在路由系统url上一定要记得加上起始终止符
9、视图:request请求都拿到了些什么?
  request.POST POST里面可能拿不到数据,但是在body中一定会拿到数据
  request.body
  request.GET
  request.path_info
  request.method
  request.session
  request.cookies
  ....
10、Form验证
  创建规则:
  类:
    字段:    

        required=True,
        min_length=3,
        max_length=18,
        error_messages={
            'required': '密码不能为空',
            'min_length': '密码长度不能小于3',             'max_length': '密码长度不能大于18',             'invalid': '密码格式错误',         },

      validators=[RegexValidator('\d+','只能是数字') ]
11、数据库操作
  13个API操作
    all,filter,get,values,values_list,fast,last,distinct,reverse,include,order_by, exist,count
    另加2个:only、refer
    FK ManyToMany
12、模板
  自定义过滤器和标签
  1、常见一个templatetags文件夹
  2、在该文件夹中随便创建一个py文件
  3、在使用自定义simple_tag和filter的html文件中导入之前创建的 my_tags.py
  3、{% load my_tags %} 
  自定义过滤器函数的参数只能两个,可以进行逻辑判断
  自定义标签无参数限制,不能进行逻辑判断

13. Session和Cookie是什么?什么区别和关系?Session原理?
由于http无状态,当请求进来的时候不会保存状态,当每次访问的时候就不知道是谁进来了,这就引出了cookie
cookie的原理:
  服务器产生内容,浏览器收到请求后保存在浏览器;
  当浏览器再次访问时,浏览器会自动带上cookie,
  这样服务器就能通过cookie的内容来判断这个是“谁”了。
The principle session:
  session will be saved on the server, so relatively safe
nutshell: cookie to make up for the lack of http stateless, let the server know to the people "who";
       but the cookie in the form of text stored locally own security poor;
     so we can identify different users by cookie, corresponding saving private information and text than 4096 bytes in the session.

In addition, the above mentioned cookie and session commonality is actually something that is not limited to language and framework
14. What is template inheritance, what good is?

  Template inheritance {% extends "base.html"%}

   Benefits: reduce the code


Guess you like

Origin www.cnblogs.com/maaosheng/p/11621476.html