摘要: 首先要导入生成图片相关模块: from PIL import Image, ImageDraw, ImageFont """ Image:生成图片 ImageDraw:能够在图片上乱涂乱画 ImageFont:控制字体样式 """ 为图片生成随机三基色 def get_random(): retur 阅读全文
posted @ 2023-11-12 21:02 wellplayed 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 代码示例: # HTML部分 <form action=""> <div class="form-group"> <label for="id_file"> 用户头像 {% load static %} <img src="{% static 'img/default.png' %}" alt="" 阅读全文
posted @ 2023-11-10 20:50 wellplayed 阅读(14) 评论(0) 推荐(0) 编辑
摘要: 正常我们想要从文件 myfile 导入模块 b 时,我们会使用: from myfile import b 接下来介绍另一种导入方式,能够用字符串来导入模块: # 首先导入importlib模块 import importlib res = 'myflie.b' importlib.import_m 阅读全文
posted @ 2023-11-09 19:04 wellplayed 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 第一步:后端配置 首先创建一个utils文件夹 在utils文件夹内创建一个py文件——mypage.py 书写代码: class Pagination(object): def __init__(self, current_page, all_count, per_page_num=10, pag 阅读全文
posted @ 2023-11-07 21:15 wellplayed 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 提示:当你想要批量插入数据的时候,使用orm给你提供的bulk_create方法能够大大的减少操作时间 普通插入: 先给Book插入一千条数据. 再将所有的数据查询并展示到前端页面 for i in range(1000): models.Book.objects.create(title='第%s 阅读全文
posted @ 2023-11-07 20:55 wellplayed 阅读(52) 评论(0) 推荐(0) 编辑
摘要: Q查询 作用: filter的字段筛选条件指定多个, 默认是and连接. 要实现or或者not需要借助Q查询 首先要导入模块 from django.db.models import Q Q(字段__条件=值) 连接条件:and or not # and的3种情况 1. filter中指定多个参数逗 阅读全文
posted @ 2023-11-06 21:24 wellplayed 阅读(587) 评论(0) 推荐(1) 编辑
摘要: F查询 作用: 能够帮助你直接获取到表中某个字段对应的数据 首先要导入模块 from django.db.models import F 用法一:查询卖出数大于库存数的书籍 res = models.Book.objects.filter(sale__gt=F('stock')) print(res 阅读全文
posted @ 2023-11-06 21:08 wellplayed 阅读(59) 评论(0) 推荐(1) 编辑
摘要: 使用方式: 将页面的某一个局部当成模块的形式,哪个地方需要就可以直接导入使用即可 导入方式如下: 首先写好要导入的HTML页面 之后在需要导入处书写代码: {% include '被导入的页面.html' %} 阅读全文
posted @ 2023-11-06 17:14 wellplayed 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 可能是复制的时候class内缺少了 bs-example-modal-lg 导致的 修改代码如下: <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModa 阅读全文
posted @ 2023-11-01 17:09 wellplayed 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 一. 正常函数版本的思路 1. notify.py def wechat(content): print('微信通知:%s'%content) def qq(content): print('qq通知:%s'%content) def email(content): print('邮箱通知:%s'% 阅读全文
posted @ 2023-10-29 21:24 wellplayed 阅读(11) 评论(0) 推荐(2) 编辑