[ @property配合@xx.setter ]


@*.setter

python中的@*.setter装饰器可以总结为两个作用:

对要存入的数据进行预处理
设置可读属性(不可修改)

注意:@.setter装饰器必须在@property装饰器的后面,且两个被修饰的函数的名称必须保持一致, 即为函数名称。

示例1

我们使用和上文一样的测试类,现在我们需要在数据存入user.age前先对其+5,利用@*.setter装饰器我们可以这样写:

class User():
    def __init__(self, name, age):
        self.name = name
        self._age = age

    

< Read more >

[ Django-TemplateView类 ]


源码TemplateView

class TemplateView(TemplateResponseMixin, ContextMixin, View):
    """
    Render a template. Pass keyword arguments from the URLconf to the context.
    """

    def get(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)
 

< Read more >

[ git撤销操作 ]


结构

  1. disk 本地硬盘
  2. staging 缓存区域
  3. local 本地的git
  4. remote 远端的git 结构

1. 撤销硬盘上的修改

git restore <changed_file>

1

2. 使用了add之后

2.1撤销add

git restore --staged <changed_file>

2.1

2.2撤销add + 本地

HEAD为最近的一次修改

git checkout HEAD <changed_file>

2.2

3. 使用了commit之后

  • 注意点: reset最好在自己的个人分支使用
  • 回退2个使用HEAD~2就行

< Read more >

[ Flask配置跨域 ]


使用添加请求头的方法实现

在每次响应的时候, 添加响应头, 配置实现

from flask import Flask, views, jsonify, make_response
from flask_wtf.csrf import generate_csrf

app = Flask(__name__)

# 基础跨域使用请求头实现

class TestView(views.MethodView):
    def get(self):
        data = jsonify({
            "code": 200,
            &qu

< Read more >

[ Mysql8用户连接配置 ]


  1. 先使用mysql数据库 use mysql;

  2. 运行远程连接 GRANT ALL ON . TO 'root'@'%'; GRANT REPLICATION SLAVE ON . TO 'root'@'%';

  3. 查看所允许的访问地址

  4. 修改所允许的访问地址,即可 update user set host='%' where user='root';

  5. 查看密码加密方式 select host, user, plugin from user;

  6. 修改密码的加密方式 alter user 'root'@'%' identified with mysql_native_passwor

< Read more >

[ Mysql事务 ]


事务嵌套的两种方法

参考事务操作

-- 第一个事务 --
BEGIN;
    update yyy;
        -- 第两个事务 ---
        begin;
            update xxx;
        commit;
    update zzz;
commit;

注意事项:

正常情况下mysql不存在事务的嵌套 当第一个事务执行, 遇到了第二个事务begin等代码 就会自动把第一个事务提交,去执行第二个事务 执行完第二个事务, 后面的代码相当于是没有事务了 导致割裂

场景1

  1. 融入外界的事务

    相当于把内部事务的begin, commit删除了 相

< Read more >

[ Mysql数据库备份 ]


基本操作

mysqldump -u root -p[密码] --databases 库名1 [库名2] ... > /备份路径/备份文件名.sql   
#导出的就是数据库脚本文件

例:
mysqldump -u root -p --databases liu > /opt/kgc.sql       #备份一个kgc库
mysqldump -u root -p --databases mysql li > /opt/mysql-kgc.sql    #备份mysql与 kgc两个库

尝试使用sh脚本备份docker里的mysql

# 保留10天数据,
# mysql8

< Read more >