- 博客(25)
- 收藏
- 关注
原创 python操作excel编号自增加1
在想要生成序号的xlsx文档前面加上序号字段这里我调的是坐标在0.0的位置上,输入的列是表格的A列import pandas as pddef auto_unmber(filename): res = pd.read_excel(filename, skiprows=0, usecols="A:A", index_col=None, dtype={'序号': str}) for i in res.index: res['序号']....
2022-04-16 17:09:11
2352
原创 Django编号生成器
from rest_framework.response import Responsefrom rest_framework.views import APIView# 编号生成器class GetNumber(APIView): def post(self, request): # 获取父级id pid = request.data.get('pid') if not pid: return Response({.
2021-10-09 11:34:45
783
原创 基于jwt模块实现登录功能
view代码from rest_framework.views import APIViewfrom rest_framework.response import Responseclass Login(APIView): ''' 登录模块 ''' def post(self,request): # 获取用户名 name = request.data.get('name') # 获取密码 passw
2021-10-09 10:50:57
283
原创 jwt万能类
可以用在多个框架当中,不需要再使用一个框架就使用框架拓展的jwt模块jwt.py代码# jwt万能类import jwtimport datetimefrom simulation_datas.settings import SECRET_KEY# from apps.user.models import Userclass JwtClass(object): # 加密token def create_token(self, user_number):
2021-10-09 10:26:03
137
原创 Django的APIView增删改查
view代码:import osimport shutilfrom django.http import StreamingHttpResponse, FileResponse, HttpResponsefrom django.shortcuts import render# Create your views here.from rest_framework.response import Responsefrom rest_framework.views import APIVie
2021-10-08 23:46:21
441
原创 ‘QueryDict‘ object is not callable
querydict是不可被调用的把abc= request.data('abc')改成 abc =request.data['abc']
2021-08-13 14:19:51
652
原创 Django树形菜单无限分类
models代码:from django.db import models# Create your models here.class OrganizeTable(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=500) pid = models.IntegerField() class Meta: db_ta
2021-08-02 17:19:44
651
原创 Django注册模块
models代码:from django.contrib.auth.models import AbstractUserclass User(AbstractUser): name = models.CharField(max_length=64) pwd = models.CharField(max_length=64) wechat = models.CharField(max_length=32) phone = models.CharField(max_
2021-08-02 17:04:58
326
原创 解决AssertionError at /xxx/xxx xxx missing “Meta“ attribute
解决AssertionError at /xxx/ Class xxx missing "Meta" attribute序列化器没有加或者写错以下字段: class Meta: model = User fields = ["id", "name"]
2021-08-02 16:31:21
723
原创 解决:AssertionError: (“Creating a ModelSerializer without either the ‘fields’ attribute or the
解决:("Creating a ModelSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = '__all__' to the CateSer serializer.",)序列化器没有加或者写错以下字段fields = '__all
2021-08-02 16:27:11
913
原创 解决django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are no
Django出现django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.问题看一下你
2021-08-02 14:11:19
574
2
原创 Django登录功能实现
本章采用的是携带jwt的方式首先我们需要搭建好我们的目录结构,如下图所示:utils代码:from apps import modelsdef jwt_response_payload_handler(token, user=None, request=None): """ 自定义jwt认证成功返回数据 token: jwt 字符串 user: 当前登录用户对象 request: 当前请求对象 """ return {
2021-08-01 23:53:43
425
1
转载 python拷贝指定文件夹或文件到指定目录
import osimport shutilprimary_dir = r'原始文件夹'target_dir = r'目标文件夹'def str_change(str): if not 'bin' in str: return str else: aa, bb = str.split('bin') return aa + bbdef func_copy(primary_dir, target_dir): # 拷贝方法 把.
2021-07-30 10:31:07
5469
2
原创 Django实现压缩文件或文件夹
django实现zip格式压缩文件或文件夹view视图代码:import osimport zipfilefrom django.http import HttpResponsedef zip_ya(startdir): startdir = r"C:\Users\17513\Desktop\aaa" # 要压缩的文件夹路径 file_news = startdir +'.zip' z = zipfile.ZipFile(file_news, 'w', zipfil
2021-07-30 10:19:29
1100
原创 解决:AssertionError at /xxx/Class xxx missing “Meta.model“
看一下你的代码结构,这两个地方有没有书写错误
2021-07-29 17:20:29
391
原创 Django日志配置
django开发文档日志配置settings日志配置:# 日志配置LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { # 日志的处理格式 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s' },
2021-07-29 11:51:41
205
原创 Django后端图片上传到前端页面并展示
这里用到的是base64的形式展示views视图代码:import osimport base64from rest_framework.views import APIViewfrom rest_framework.response import Responseclass ONE(APIView): def get(self, request): dir_name = request.GET.get('dir_name') request.
2021-07-29 11:17:30
2808
原创 解决RuntimeError: You called this URL via POST, but the URL doesn‘t end in a slash and you have APPEND
访问路由是要加上斜杠" / "urlpatterns = [ path('admin/', admin.site.urls), # path('', views.index.as_view()), path('upload/', views.upload,name='upload'), # path('download_template/', views.download_template,name='download'), # path('', views.i
2021-07-29 09:15:36
415
原创 Django实现文件上传功能,不使用数据库
def upload(request): if request.method == "POST": obj = request.FILES.get("test") import os f = open(os.path.join(settings.MEDIA_ROOT, 'upload', obj.name), 'wb') for chunk in obj.chunks(): f.write(chunk) .
2021-07-28 23:42:24
519
原创 mongodb无法启动:exception: connect failed,exiting with code 1解决方式
mongodb无法启动:exception: connect failed,exiting with code 1问题:启动mongo是出现以下情况:首先打开终端,查看一下mongo的日志信息,查看代码如下:sudo vim /var/log/mongodb/mongod.log 如果日志中出现以下问题导致启动失败:在终端执行代码:sudo chown -R mongodb:mongodb /var/lib/mongodb如果不行的话,看一看日志中有什么其他错误信息,根据反馈的错误信息
2021-03-23 17:44:28
3552
原创 django:mysql Error Code : 1060 Duplicate column name ‘user_id‘问题
mysql Error Code : 1060 Duplicate column name 'user_id’问题解决方式一﹑先看一下django的虚拟环境与命令栏是否匹配如果不匹配切换到虚拟环境或者已安装的解释器下执行解决方式二﹑将migrations文件夹下除了__init__.py以外全部删掉然后执行python manage.py makemigrationspython manage.py migrate如果都不行的话可能是django版本问题,或者试试将报错数据库drop
2020-12-15 19:32:51
1126
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人