
Python
文章平均质量分 96
qq_道可道
助人乃快乐之本
展开
-
Mac更换brew国内源及python环境配置集合
Mac 下 brew 切换为国内源https://www.cnblogs.com/daodaotest/p/12635957.html在Mac上Python多版本切换https://www.cnblogs.com/terrylin/p/12076918.htmlPycharm选择pyenv安装的Python版本https://www.cnblogs.com/blackmatrix/p/5603888.html原创 2020-11-11 16:13:05 · 801 阅读 · 0 评论 -
django返回数据库str类型数据并转json
1.取出数据库里的数据并将字符串转为字典,需求1:给浏览器返回json数据project = Project.objects.filter(project=name).first()project_ser = ProjectSerializer(project)data = project_ser.data['json_template']to_dict = eval(data)return Response(content_type='application/json', data=to_di原创 2020-10-28 16:37:58 · 712 阅读 · 0 评论 -
python3批量修改目录下json文件数据
#!/usr/bin/pythonimport jsonimport ospath = ‘./templates/’for fpathe,dirs,fs in os.walk(path):for f in fs:print(os.path.join(fpathe,f)) with open(os.path.join(fpathe,f),'r',encoding='utf8')as fp: json_data = json.load(fp) #print('原创 2020-09-29 13:41:07 · 605 阅读 · 0 评论 -
使用pandas计算mysql表中日环比
mysql数据源INSERT INTO `dingtalk`.`dba_tables_info`(`id`, `table_schema`, `table_name`, `table_comment`, `table_rows`, `tablespace_size`, `query_time`) VALUES (1, 'dingtalk', 'auth_group', '', 100, 32768, '2020-08-13 20:12:41');INSERT INTO `dingtalk`.`dba_t原创 2020-08-14 14:43:30 · 281 阅读 · 0 评论 -
Django rest framework使用ModelViewSet视图集
ModelViewSet是封装度最高的DRF的视图类。包含了增删改查中的所有接口操作。它继承自GenericViewSet、ListModelMixin、RetrieveModelMixin、CreateModelMixin、UpdateModelMixin、DestoryModelMixin。使用视图集,可以将一系列逻辑相关的动作放到一个类中:list() 提供一组数据retrieve() 提供单个数据(详情)create() 创建数据update() 更新数据destory() 删除数据原创 2020-08-06 15:50:06 · 1780 阅读 · 0 评论 -
Django使用celery小记
参考官网:https://docs.celeryproject.org/en/4.4.3/django/first-steps-with-django.html版本号python 3.7amqp 2.6.0celery 4.4.3Django 2.2django-celery 3.3.1flower 0.9.4Celery是基于Python开发的一个分布式任务队列框架,采用生产者-消原创 2020-06-17 15:02:49 · 351 阅读 · 0 评论 -
django设置允许跨域访问
当使用vue前后端分离时,后端需要配置允许跨域访问,否则前端请求会报错。安装包pip install django-cors-headers修改settings.pyINSTALLED_APPS = [ 'corsheaders',]MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware',]CORS_ORIGIN_ALLOW_ALL = TrueCORS_ALLOW_CREDENTIALS = True...原创 2020-06-05 13:53:41 · 390 阅读 · 0 评论 -
django 简单搜索与分页
默认情况下,搜索将使用不区分大小写的部分匹配。 搜索参数可以包含多个搜索项,它们应该是空格和/或逗号分隔。 如果使用多个搜索项,则仅当所有提供的条款匹配时,才会在列表中返回对象。默认情况下,搜索参数被命名为“search”,但这可能会被SEARCH_PARAM设置覆盖。The search behavior may be restricted by prepending various characters to the search_fields.可以通过在search_fields中加入一些字符来限原创 2020-05-29 13:32:21 · 245 阅读 · 0 评论 -
django rest framework 分页
from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination, CursorPaginationfrom rest_framework.response import Response‘’’自定义分页:基础分页http://127.0.0.1:8000/api/v1/work_order?size=10&page=1‘’’class MyPagination(PageNumberPagi原创 2020-05-28 16:02:06 · 400 阅读 · 0 评论 -
django rest framework token认证/授权/频率限速
新建myapp/utils/auth.py文件# 导入需要继承的基类BaseAuthenticationfrom rest_framework.authentication import BaseAuthenticationfrom rest_framework.exceptions import AuthenticationFailedfrom myapp import models...原创 2020-04-26 11:33:28 · 257 阅读 · 0 评论 -
安装django xadmin
01-下载源码pip install https://codeload.github.com/sshwsfc/xadmin/zip/django202-配置settings.py# 引入下面三个appINSTALLED_APPS = [ .... 'xadmin', 'crispy_forms', 'reversion', ] # 修改使用中文界面L...原创 2020-04-15 15:26:57 · 182 阅读 · 0 评论 -
pycharm创建venv环境django项目加demo
windows系统django创建项目相关操作记录。1.通过pycharm创建venv环境2.进入venv项目终端安装相关包cd D:\project\djangoadmin\venv\Scriptsactivate.batpip install django==2.1 -i https://pypi.tuna.tsinghua.edu.cn/simplepip install dj...原创 2020-03-14 17:05:27 · 3581 阅读 · 0 评论 -
python对接钉钉加解密实践
python对接钉钉加解密实战需求参考文档开始代码结构app.pydevops/__init__.pydevops/api/event_callback.pydevops/api/test.py注意附内网穿透工具需求通过钉钉的自定义审批流,触发我们自己写的接口(系统or平台)触发后续动作。1.这里win10系统,用的python3.7, web框架flask,用的三方sdk,解决加解密问题...原创 2020-03-12 14:21:11 · 1551 阅读 · 2 评论