自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

帅的飞起的博客

人生苦短,我用python

  • 博客(35)
  • 收藏
  • 关注

原创 执行python manage.py mirate,报错AttributeError: ‘tuple‘ object has no attribute ‘startswith‘

将生成的迁移文件删掉,重新执行python manage.py makemigrations,python manage.py mirate,ok。导致执行python manage.py makemigrations 生成的迁移文件中db_table是个元组。如果提示表已存在,将存在的表删掉,重新执行python manage.py mirate。db_table = ‘test’,多加了个逗号。models.py 中。

2023-08-14 17:39:54 198

原创 Django使用uwsgi+nginx部署,admin没有样式解决办法

解决django项目在服务器部署后,admin没有样式问题

2023-08-04 08:45:49 1701

原创 python使用mysql,防止SQL注入

python使用mysql防止SQL注入

2023-04-24 09:53:34 758 1

原创 使用python生成excel表格

【代码】使用python生成excel表格。

2023-02-03 08:51:24 874

原创 json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1

最近用postman调用接口时候报错 json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 3)如下图所示:原因:这个json是从微信复制过来粘贴到postman上的,微信粘贴过来的不是标准的json格式解决这个问题最简单的方式是,点击下postman右边的beautify,重新测试okdef test(request): if re

2022-05-06 19:07:14 3627

原创 Error loading cx_Oracle module: No module named ‘cx_Oracle‘

ImportError: No module named cx_Oracle需要安装或者升级oracle模块直接pip install cx_Oracle会安装不成功在setting中安装也没成功安装时需要指定版本pip install cx_Oracle==7.3.0即可

2022-03-16 18:21:48 2006

原创 django使用mysql的坑,AttributeError: ‘str’ object has no attribute ‘decode’

django使用mysql的坑坑1.django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?解决方法先安装pymysqlpip install pymysql在你的项目目录下__init__.py,添加下面一段代码import pymysqlpymysql.install_as_MySQLdb()坑2.django.core.excepti

2021-12-08 16:50:35 438

原创 django使用xadmin

django使用xadminxadmin特点:1.支持在多种屏幕上无缝浏览2.内置功能丰富3.强大的插件系统4.可以直接在后台对表进行增删改查安装xadmin注意:是pip install xadmin-py3pip install xadmin-py3pip install xadmin-py3重要的事说三遍!!!配置xadmin在你的项目目录下settings.py中,添加xadmin,crispy_forms(这个是依赖包)INSTALLED_APPS = [ 'dj

2021-08-10 15:53:34 1877 1

原创 python数字转百分比%,保留小数点后两位

python数字转百分比%,保留小数点后两位zrs = 215nan = 100nan_zb = "%.2f"%(float(nan/zrs)*100)+"%"print(type(nan_zb))print("男生占总人数的: ",nan_zb)#结果:# <class 'str'># 男生占总人数的: 46.51%

2021-07-30 11:16:21 4198

原创 Python开发工作中实用时间(datetime,time)转化小技巧

Python开发工作中使用时间datetime,time转化小技巧# Python开发工作中使用时间转化小技巧:# 时间戳转日期# 日期转时间戳# 格式化时间# 指定格式获取当前时间# 时间戳转成具体时间,需要两个函数:# time.localtime:将时间戳转成时间元组形式# time.strftime:将时间元组数据转成我们需要的形式import timenow_timestamp = time.time()print(now_timestamp)# 1614568419.4

2021-03-01 12:00:01 212

原创 python中list的切片赋值和省略

python中list的切片赋值和省略l = list(range(10))print(l)# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]l[2:5] = [20, 30]print(l)# [0, 1, 20, 30, 5, 6, 7, 8, 9]del l[5:7]print(l)# [0, 1, 20, 30, 5, 8, 9]print(l[3::2])# [30, 8]l[3::2] = [11, 22]print(l)# [0, 1, 20, 11

2021-02-01 15:04:37 563 1

原创 python中的具名元组collections.namedtuple

python中的具名元组collections.namedtuplefrom collections import namedtuple# 具名元组是collections.namedtuple中的一个工厂函数,# 用来构建一个带字段名的元组和一个有名字的类City = namedtuple("City", "city country pop coordinates")tokyo = City("Tokyo", "JP", "36.6", (35.6, 129.7))print(type(tok

2021-02-01 15:02:09 153

原创 python实现获取时间段datetime内的年月并倒叙排序

python实现获取时间段内的年月并倒叙排序import datetimedef get_date_list(start_date, end_date): date_list = [] # 字符串转换成datatime格式 如果你的入参是20200101 下面格式化要加上%d # start_date = datetime.datetime.strptime(start_date, '%Y%m%d') start_date = datetime.datetime.s

2021-01-19 11:46:28 1322 1

原创 python实现按照list中字典dict的某key合并去重并排序

python实现按照list中字典dict的某key合并去重并排序list1 = [{"name": "zzz", "date": 202101, "age": 16, "gender": None}, {"name": "zzz", "date": 202102, "age": 18, "gender": None}]list2 = [{"name": "zzz", "date": 202101, "age": None, "gender": "man"}, {"n

2021-01-18 17:34:27 2000

原创 python之字典操作

python之字典操作dict_test1 = { "name": "john", "gender": "man", "age": 20, "height": 1.78, "weight": 70}# 从字典中取出键对应的值name = dict_test1["name"]print(name)# john# 从字典中取出键对应的值age = dict_test1.get("age")print(age)# 20# 以列表返回可遍历的(键,

2021-01-12 16:21:57 261

原创 python字符串str操作大全

str1 = " hello world, I am python "str2 = str1.find(“d”)print(str2)10 如果是返回开始的索引值,否则返回-1str3 = str1.index(“l”)print(str3)2 跟find()方法一样,只不过如果str不在 mystr中会报一个异常str4 = str1.count(‘l’)print(str4)3 返回 str在start和end之间 在 mystr里面出现的次数str5 = str1.replac

2021-01-12 15:02:41 469

原创 python字符串str拼接

python字符串str拼接简单粗暴地+拼接,必须是strstr01 = "hello "str02 = "world!"str03 = str01 + str02print(str03)# hello world!用,拼接这样出来的是个元组str04 = str01, str02print(str04)# ('hello ', 'world!') 这样拼接出来的是个元组使用%拼接str1 = "hello"str2 = "world"print("%s,%s" % (str

2021-01-12 11:43:59 7727 1

原创 Python中UUID生成的原理和用法

Python-UUIDUUID是基于当前时间、计数器(counter)和硬件标识(通常为无线网卡的MAC地址)等数据计算生成的,因为它们是不会被复制的独特标识符但是如果只传这个已

2021-01-08 17:10:30 5462

原创 Python连接mysql数据库获取数据

Python连接mysql数据库获取数据import MySQLdbmydb = MySQLdb.connect(host="localhost", user="root", password="Python@123", db="api_test",charset="utf8") # 如果中文显示乱码,则需要添加charset = "utf8"cursor = mydb.cursor()mysql = """select * from test01

2021-01-07 18:43:44 1025

原创 Python实现base64编码文件转化为jpg/png/jpeg/格式图片

Python实现base64文件转化为jpg/png/jpeg/格式图片这个base64文件是图片转化的才行,不是随便找个base64文件都行的base64图片文件qiaoba.py/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//2wBDAQ4ODhMREyYVFSZPNS01T09PT09PT09PT09PT0

2021-01-07 17:33:13 12629

原创 Python实现jpg/png/jpeg图片转base64编码文件

python实现图片转base64文件#python实现图片转base64文件# 打开图片文件(可以是jpg/png/JPEG格式)转为二进制文件with open("qiaoba.jpg", "rb") as f: # 使用base64进行加密 data = base64.b64encode(f.read()) print(data) # 写到文件中 file = open('qiaoba.py', 'wb') file.write(data)图片

2021-01-07 17:26:06 8059

原创 用python实现AES-ECB加密解密

用python实现AES-ECB加解密# AES-ECB加密import base64import hashlibimport jsonfrom Crypto.Cipher import AESsecret = '1111111111111111'BLOCK_SIZE = 16 # Bytes# 补位,补齐16位pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * \ chr(BLOCK_S

2021-01-06 12:02:32 5742 4

原创 python将两个列表list[]合成一个字典dict{}

将两个列表list[]合成一个字典dict{}list1 = ["name", "gender", "age"]list2 = ["张三", "男", "23"]dict_data = dict(zip(list1, list2))print(dict_data)# 结果{'name': '张三', 'gender': '男', 'age': '23'}

2021-01-05 12:02:30 4156

原创 python对list[]列表中的dict{}字典排序

python对list[]列表中的dict{}字典排序data1 = [{"date": "2010-10-12", "name": "张三"}, {"date": "2010-09-12", "name": "李四"}, {"date": "2010-10-01", "name": "王五"}]# reverse=False 不反转,正序从小到大排序 如果等于True倒叙排,从大到小data2 = sorted(data1, key=lambda keys: keys.get("

2021-01-05 11:42:29 1308

原创 UnicodeDecodeError ‘gbk‘ codec can‘t decode byte 0x80 in position 8 illegal mult报错及解决方法

UnicodeDecodeError ‘gbk’ codec can’t decode byte 0x80 in position 8 illegal mult报错及解决方法解决方法# 原因文件格式是'gbk'修改代码,加encoding='utf-8'即可f = open('test001.txt', 'r',encoding='utf-8')f.read()

2021-01-04 17:17:23 2810

原创 django实现多个app在后台自定义显示名称

django实现多个app在后台自定义显示名称在apps中添加# Interface_App下的apps.pyfrom django.apps import AppConfigclass InterfaceAppConfig(AppConfig): # app 名称 name = 'Interface_App' # verbose_name 你想要显示的名称 verbose_name = "接口管理"# Interface_Manage下的apps.pyfrom d

2021-01-04 17:10:07 453

原创 Django连接mysql数据库settings配置及使用

Django连接mysql数据库settings配置及使用setting中DATABASES需要配置成以下DATABASES = { 'my_test': { # 说明你要连的库为mysql 'ENGINE': 'django.db.backends.mysql', # 数据库名称 'NAME': 'api_test', # IP 本地为127.0.0.1 'HOST':'127.0.0.1',

2021-01-04 16:53:26 2249

原创 使用python判断文件是否是excel格式

python实现上传的文件是否是excel格式判断file_data = "学生统计表.xlxs"file_name = file_data.split(".")[0]file_type = file_data.split(".")[1]print(file_name, file_type)if file_type in ["xlxs","xls"]: print("file_type is excle")

2021-01-04 16:17:27 4272 1

原创 用Django实现文件的上传下载,前后端不分离

用Django实现文件的上传下载,前后端不分离首先需要在setting中加入下面两行代码,将media加入到BASE_DIR中MEDIA_URL = '/media/'MEDIA_ROOT = os.path.join(BASE_DIR, 'media')在你项目的urls中加入下面一行url(r'^media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}, name='media'),# 完整的urlsfrom dja

2021-01-04 16:04:07 1849 12

原创 使用%格式化多层{},json格式的参数

使用%格式化多层{}字典的参数.format只适合格式一层{}的参数,下面用%格式化json格式的参数req_data = {'bdcqzh': '1234', 'xm': 'lisi', 'get_token': '1233445','sfzhm': '4111111111111'}data_request = { "token": "%(get_token)s", "data": { "name": "portnam

2021-01-04 09:22:34 433 1

原创 python使用.format格式化json格式的入参

使用.format格式化json格式的入参(.format只适合格式化只有一层{}的参数,例如像这种的有多层的{}字典形式data= {data:{"name":{name},"gender":{gender}}},无法格式化)sql = "select * from userinfo where t.name = {name} and t.gender = {gender}"req_data = {"name": "zhangsan", "gender": "man"}res_data = sq

2021-01-04 09:17:37 2021

原创 django中admin设置-让你的admin后台更加漂亮实用

django中admin设置-让你的admin后台更加漂亮实用from django.contrib import adminfrom Interface_App.models import Sql_Interface# 登录时显示的名称admin.site.site_header = '平台管理后台1111'![登录时显示的名称](https://img-blog.csdnimg.cn/20201230105941608.png?x-oss-process=image/watermark,ty

2020-12-30 11:12:47 1842 2

原创 python提取xml格式的出参并转成dict

python提取xml格式的出参并转成dict# python提取xml格式的出参并转成dictxml_data = """<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:QueryResponse xmlns:ns2="http://www.topwalk.com"> <QueryData>

2020-12-30 10:21:02 720 2

原创 python使用RSA实现非对称加解密

python使用RSA非对称加解密# python使用RSA非对称加解密import base64from Crypto import Randomfrom Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5from Crypto.PublicKey import RSA# 伪随机数生成器random_generator = Random.new().read# rsa算法生成实例rsa = RSA.generate(1024, r

2020-12-30 10:09:01 541

原创 python中使用schema对json格式的入参进行校验

python中使用schema对json格式的入参进行校from schema import Schema, Optional, And, Or入参的数据为:request_data = { "appId": "sxxxxxx", # "appKey": "cbxxxxxxxxxx-xxxxxxxxxx"9f", "HTBH": "C00xxxxxxx", "GMFXX": [ { "XM": "宋X",

2020-12-30 09:41:45 1634 2

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除