摘要:
设置参数 def fun(request): data = [ { "name": "tes3", "id": 12, "ip": "10.10.12.120, 10.10.12.121" }, { "name": "test2", "id": 13, "ip": "10.10.12.1,10.10 阅读全文
摘要:
1 def check_connect(host, port): 2 sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 3 sk.settimeout(2) 4 status = 0 5 try: 6 sk.connect((host, p 阅读全文
摘要:
例:setting配置 import logging import os # LOG_DIR = "/var/log/dt_logs" LOG_DIR = "./" # if not os.path.exists(LOG_DIR): # os.mkdir(LOG_DIR) LOGGING = { " 阅读全文
摘要:
datetime 模块中 常用 second 和 total_seconds() 来获取时间差 seconds 忽略天 只看时分秒 total_seconds() 真正的时间差 包含天 1. 模型创建时间字段 create_time = models.DateTimeField("创建时间", nu 阅读全文
摘要:
视图函数 中间件类 class JsonMiddleware(MiddlewareMixin): def process_response(self, request, response): if isinstance(response, HttpResponse): return response 阅读全文
摘要:
1. get方式获取: res = request.GET.get("name", " ") GET提交,请求的数据会附在URL之后(就是把数据放置在HTTP协议头中),以?分割URL和传输数据,多个参数用&连接 2. 以表单方式传数据 name = request.POST.get("name", 阅读全文
摘要:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 1. os.path.abspath(file)返回的是.py文件的绝对路径,也就是settings.py这个文件路径 2. os.path.dirname( 阅读全文
摘要:
1. 安装:pip install supervisor 2. 重定向默认配置:echo_supervisord_conf > /etc/supervisord.conf 3. 修改配置文件目录,修改tmp目录 4. 启动服务:supervisord -c /etc/supervisord.conf 阅读全文
摘要:
先将一个文件内容读取,再写入至另外一个文件 w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。 w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。 with open("/data/test.txt", "r", 阅读全文