django 对model 模型的操作返回结果为QuerySet,可以用下面的方法序列化返回给前端
>>> from cost_app.models import AllMonthReport
>>> from django.core.serializers import serialize
>>> all_amount = AllMonthReport.objects.all().order_by('-month', 'item')
>>> json_data = serialize(
分类标签归档:python
django 对model 模型的操作返回结果为QuerySet,可以用下面的方法序列化返回给前端
>>> from cost_app.models import AllMonthReport
>>> from django.core.serializers import serialize
>>> all_amount = AllMonthReport.objects.all().order_by('-month', 'item')
>>> json_data = serialize(
aggregate 是聚合的意思
# 导入常见的聚合函数 SUM, AVG, COUNT, MAX, MIN
python3.8 manage.py shell
>>> from cost_app.models import MonthCost
>>> from django.db.models import Sum, Avg, Count, Max, Min
>>> amount = MonthCost.objects.filter(account__id=8).aggregate(Sum('Payment
pip install redispy
`
# _*_coding:utf-8_*_
import redis
class TestBase(object):
"""
定义初始化连接,作为基类,供其他包装类使用
"""
def __init__(self):
self.r = redis.StrictRedis(host='localhost', port=6379, db=0)
class TestString(Tes
1、安装snmp 客户端 Centos
yum -y install net-snmp-utils
#snmpwalk 简单实用
snmpwalk -v 2c -c public 192.168.31.225
python
pip install -i http://pypi.douban.com/simple --trusted-host=pypi.douban.com pysnmp
2、pysnmp的使用
In [1]: from pysnmp.entity.rfc3413.oneliner import cmdgen
pip install -i https://pypi.douban.com/simple --trusted-host=pypi.douban.com PyYAML
#####
#扫描主机配置信息
#####
hostsinfo :
# 主机段,EXP:['192.168.6'] or ['192.168.1',192.168.2]
nets : ['192.168.1']
# 端口段
ports : "22,222,2222,222
pip install paramiko
In [1]: import paramiko
In [2]: ssh = paramiko.SSHClient()
Linux系统下安装
yum -y install nmap
python 模块安装
pip install python-nmap
linux 下面
macdeMac:~ mac$ nmap -n -PS -PE 192.168.31.225
Starting Nmap 7.80 ( https://nmap.org ) at 2020-01-21 17:43 CST
Nmap scan report for 192.168.31.225
Host is up (0.012s latency).
Not shown: 995 closed ports
PORT
# Logging 配置
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '[%(levelname)s][%(asctime)s][%(filename)s][%(funcName)s][%(lineno)d]> %(message)s&
1、修改title 和 footer、应用的全局图标
# /extra_apps/xadmin/adminx.py
from dn_app.models import Company, MobilePhone, DnManager
class GlobalSetting(object):
# 设置base_site.html 的Title
site_title = 'xx管理后台'
site_footer = '我的公司'
global_search_models = [Company, MobilePhone, DnManag
1、环境安装 环境最好保持一致,要不然会碰到很多坑,浪费时间。 Python 3.6.2 django 2.0 python 3.6.2 的虚拟环境可以参看https://www.65535.fun/article/2019/12/13/12.html 进行安装 注意:sqlite3 需要提前安装,再安装python版本,要不然认不到yum install sqlite* -y
django 2.0 安装
pip install -i https://pypi.douban.com/simple --trusted-host=pypi.douban.com django==2.0
2、xad