![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Django
我怕天黑却不怕鬼
这个作者很懒,什么都没留下…
展开
-
django 使用celery(异步/定时)发送邮件
使用celery(异步/定时)发送邮件项目结构myproject apps app1 views.py app2 views.py project settings.py celery_tasks celery.py config.py email tasks.pysettings.py# settings.py# 配置邮件发送EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBacken原创 2021-11-09 18:03:47 · 1401 阅读 · 2 评论 -
Django REST framework - 序列化组件、source、钩子函数
[Django REST framework - 序列化组件、source、钩子函数]序列化器-Serializer什么是rest_framework序列化?在写前后端不分离的项目时:我们有form组件帮我们去做数据校验我们有模板语法,从数据库取出的queryset对象不需要人为去转格式当我们写前后端分离项目的时:我们需要自己去做数据校验我们需要手动去转数据格式,因为跨平台数据传输都用json字符串,不能直接jsonqueryset对象序列化器的作用1 序列化:把python中的对象转原创 2021-08-26 09:56:46 · 1160 阅读 · 0 评论 -
django 插入库表时如何添加many-to-many字段数据
django 插入库表时如何添加many-to-many字段数据创建对象时,多对多字段不能直接通过下面的方式处理:from .models import ScheduleModel,Userusers=User.objects.filter(age__glt=19)# 这样直接写过不了,会报错: Direct assignment to the forward side of a many-to-many set is prohibitedScheduleModel.objects.create原创 2021-07-06 18:01:49 · 534 阅读 · 0 评论 -
django-crontab设置定时任务
django-crontab1、安装django-crontab$ pip install django-crontab2、在django项目settings.py中注册INSTALLED_APPS = [ ...... 'django_crontab', 'app_name']【注意】django_crontab一定要注册在应用名之前,在这里是下划线,不是短横。3、在settings.py中配置定时任务# 定时任务设置CRONJOBS = [ # 检测原创 2021-07-06 17:48:53 · 443 阅读 · 1 评论 -
Django排序方法详解介绍
Django的各种排序方法今天在公司遇到一个给通知公告置顶的需求,我就学习了一下Django如何进行排序1、如何以升序或者降序方式给查询及排序通过order_by方法实现,需要传入待排序的字段,查询语句如下User.objects.all().order_by('pk') # 升序,即从小到大User.objects.all().order_by('-pk') # 降序,即从大到小# 你可以传入多个字段给order_by方法User.objects.all().order_by('pk'原创 2021-06-29 09:56:11 · 7833 阅读 · 0 评论 -
Django项目之CKEditor富文本编辑器的使用
Django项目之CKEditor富文本编辑器的使用1.安装$ pip install django-ckeditor2.注册应用NSTALLED_APPS = [ ...... 'ckeditor', # 富⽂本编辑器 'ckeditor_uploader', # 富⽂本编辑器上传图⽚模块 ......]3.配置setting.py# 富⽂本编辑器ckeditor配置CKEDITOR_CONFIGS = { 'default': { 'toolbar': 'full'原创 2021-06-25 15:48:57 · 168 阅读 · 0 评论