Python

Python

Python

Django

Django REST framework

建议参考django rest framework官网做一遍, 具体我不再展示

总结下来 优点:

  • 不用写那么多的相同的增删改查

Celery

基于python写的任务队列 中文文档

celery和django一起 这个文档比较老旧了celery with django

更正里面的现在错误

1
2
3
python manage.py migrate celery_results
改为
python manage.py migrate django_celery_results

celery -A启动的时候会报错

1
ModuleNotFoundError: No module named 'psycopg2'

尝试安装这个模块的时候报错

1
2
3
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: 没有那个文件或目录
sudo apt-file search libpq-fe.h 
libpq-dev: /usr/include/postgresql/libpq-fe.h

从apt-file search这个命令可以发现来源于这个包libpq-dev

1
sudo apt-get install libpq-dev

建议英文可以的参考这篇官方文档

celery如何debug 使用rdb 建议参考https://www.celerycn.io/v/4.4.0/yong-hu-zhi-nan/tiao-shi-debugging

一些examples https://www.programcreek.com/python/example/59126/celery.chain

装饰器

@dataclass

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
In [16]: from dataclasses import dataclass

In [17]: @dataclass
    ...: class Name:
    ...:     gender: str
    ...:     def __post_init__(self):
    ...:         if self.gender not in ["man","woman"]:
    ...:             raise ValueError("Invalid gender")
    ...: 

In [18]: foo = Name('x')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [18], line 1
----> 1 foo = Name('x')

File <string>:4, in __init__(self, gender)

Cell In [17], line 6, in Name.__post_init__(self)
      4 def __post_init__(self):
      5     if self.gender not in ["man","woman"]:
----> 6         raise ValueError("Invalid gender")

ValueError: Invalid gender

In [19]: foo = Name('man')

In [20]: foo.gender
Out[20]: 'man'

scapy

tracert出有向图

1
2
3
# sudo scapy
res, unans = traceroute(["blog.liuliancao.com"], dport=[80, 443], maxttl=20,retry=-2)
res.graph()

tracert出地理位置地图

1
2
res, unans = traceroute(["blog.liuliancao.com"], dport=[80, 443], maxttl=20,retry=-2)
res.world_trace()

这里我失败了

绘制架构图工具