
python
zb0567
这个作者很懒,什么都没留下…
展开
-
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x97 in position 2: illegal multibyte sequence
大概率事件编码错了,可以改gbk utf-8。原创 2022-10-22 14:58:19 · 427 阅读 · 0 评论 -
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0: invalid continuation byte
就是把文件以记事本打开,然后utf-8存储,在运行,没毛病了。原创 2022-10-18 16:44:38 · 986 阅读 · 0 评论 -
python2和python3安装共存
由于我一不小心装了一个python2的64位和python3的32位,导致有部分程序跑不动,无奈只能卸载python3的32位,然后删除文件夹,下载python3的64位,重新安装,然后又遇到了python2和python3共存的问题,重新梳理一下。1、下载个人建议都去下载个64位的,虽然32位更广泛,但是很多高性能要求64位下载安装即可推荐安装 C:\2、如果安装过程勾选 add path to 变量,那么就不用动了,如果没有,需要你在环境变量里面添加Path3、修改p原创 2022-05-25 11:26:28 · 273 阅读 · 0 评论 -
Sublime Text 配置python环境
{ "cmd": ["D:/python37/python.exe","-u","$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python",}新建环境如上,把python路径改下,同时注意反斜杠~~原创 2021-10-12 22:25:05 · 220 阅读 · 0 评论 -
kali最新更新指南
1、更新源编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目:deb https://mirrors.ustc.edu.cn/kali kali-rolling main non-free contribdeb-src https://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib更改完sources.list文件后请运行sudoapt-getupdate更新索引以生效。...原创 2021-09-22 23:38:27 · 1394 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
jieba.py不是你说你想用就能用,改了吧,兄台~~~原创 2021-08-06 18:59:10 · 706 阅读 · 1 评论 -
Flask-Migrate 检测不到db.string() 等长度变化
修改migrations下的env.py 添加参数compare_type = Truecontext.configure(connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, compare_type = True, #compare_type默认为False,不检测数据变化 compa原创 2020-12-21 18:01:33 · 328 阅读 · 0 评论 -
windows7-32位系统下部署flask程序(wsgi简单快速配置)---编辑中
安装pytyon3.7C:\Users\Zfm>cd C:\Users\Zfm\AppData\Local\Programs\Python\Python37-32\Scriptscmd切换到该目录下,使用C:\Users\Zfm\AppData\Local\Programs\Python\Python37-32\Scripts>pip install mod_wsgi-4.7.1-cp37-cp37m-win32.whl提示mod_wsgi-4.7.1安装成功mod_wsgi-原创 2020-12-07 16:22:09 · 408 阅读 · 0 评论 -
python manage.py db migrate ERROR [root] Error: Target database is not up to date.
1、找到alembic(数据库中的数据表)的最新版本号, 找到文件夹migrate下的最新版本,文件名即为最新版本号(去掉末尾的_)。 更新数据库表alembic_version里version_num的字段,将该字段的值改为最新版本号再次迁移即可成功2、删除数据文件和migrate文件,重新初始化数据库。第二种1. 查看migrate的状态$: pyt...原创 2020-05-01 18:17:05 · 620 阅读 · 0 评论 -
centos里安装nginx1.16.1 & nginx反向代理 端口映射
各种依赖#gcc安装,nginx源码编译需要yum install gcc-c++#PCRE pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式yum install -y pcre pcre-devel#zlib安装,nginx 使用zlib对http包的内容进行gzipyum install -y zlib zlib-devel...转载 2020-04-15 20:10:15 · 661 阅读 · 0 评论 -
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "DROP": syntax error
这就是flask 对应 sqlite的一个坑解决方式1.修改migrations/evn.py中的方法, 添加 render_as_batch=True2、删除version下面的各种东西,3、重新执行python manage.py db init // migrate // upgrade4、(venv) D:\zz\PycharmProjects\fl...原创 2020-04-15 08:48:38 · 3200 阅读 · 0 评论 -
python-TypeError: Object of type 'Decimal' is not JSON serializable 报错
j = json.dumps(xxxxxxx,cls=DecimalEncoder)class DecimalEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): return float(o) super(Deci...转载 2020-04-06 09:51:45 · 929 阅读 · 0 评论 -
RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A
解决方法:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.action地址改为/结尾的 推荐这一种或者修改settings:APPEND_SLASH=False...原创 2020-03-26 10:53:23 · 318 阅读 · 0 评论 -
API: jquery-serialize-object is required to add form data to an existing data object
使用 Semantic-Ui API behaviors 时出现上述问题,原因是如果请求提交的是表单,需要使用serializeForm 设置。否则 input 的数据都不会发送到服务器。以上的用法如果不注意看文档中这一行提示:Structured form data requires includingmacek's serialize object.所以使用该特性时要记得...原创 2020-03-26 00:12:05 · 188 阅读 · 0 评论 -
Python中获得当前目录和上级目录
获取当前文件的路径:from os import path d = path.dirname(__file__) #返回当前文件所在的目录 # __file__ 为当前文件, 若果在ide中运行此行会报错,可改为 #d = path.dirname('.')获得某个路径的父级目录:parent_path = os.path.dirname(d) #获得d所在的目录...转载 2020-03-24 23:47:43 · 348 阅读 · 0 评论 -
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
centos7默认安装的sqlite3版本为3.7.17,我安装的django版本为django》2.2.X,要求sqlite3的版本最低为3.8.3,处理方式有两种:1.安装低版本的django2.12.升级sqlite3.方法如下:wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gztar -zxvf s...原创 2020-03-21 10:29:44 · 563 阅读 · 0 评论 -
django debug=false admin或者xadmin功能时, 一部分 css和js文件无法加载
要明白,在开发django的时候,如果设置了 DEBUG = True,django便会自动帮我们对静态文件进行路由;但是当我们设置DEBUG = False后,这一功能便没有了,因此静态文件就会出现加载失败的情况,想要让静态文件正常显示,就需要手动配置静态文件服务了。在settings文件中配置:第一种说法 这种会报错,重复包含,有悖于唯一性STATIC_URL = '/stat...原创 2020-03-21 00:43:06 · 652 阅读 · 1 评论 -
TypeError: can't subtract offset-naive and offset-aware datet
Datetime中offset-naive与offset-aware时间的计算转载 2020-03-18 01:00:06 · 2075 阅读 · 0 评论 -
CentOS 使用 runserver 启动服务器后,常驻后台运行 监控端口 杀死进程
nohup python manage.py runserver 0.0.0.0:9000 &&可以不写 nohup不行nohup python manage.py runserver 0.0.0.0:9090 > /home/stat.log 2&>1 &吐出日志根据端口查看这个进程的pidnetstat -lnp|grep 80...原创 2020-03-17 23:49:54 · 253 阅读 · 0 评论 -
Pycharm安装扩展包
Python中第三方的库(library)、模块(module),包(package)的安装方法以及ImportError: No module named1.pip install .... 一般的pycharm都自带有pip,如果没有,就去下一个pip的安装包,将安装包解压在Python的根目录,搭建好Python的环境,然后用Python来安装pip,基本上就可以在pycharm...转载 2020-03-17 23:43:37 · 859 阅读 · 0 评论 -
Pycharm Github 备份
1、注册github账号2、安装git3、PyCharm的File -> Setting,找到github,输入用户名和密码,点击test4、设置Git,把路径设置为本机git安装路径(git.exe的路径): 这个可以自动侦测5、点击VCS下的import into Version Control,找到Share Project on GitHub: 开始设置 填写名字,...原创 2020-03-17 23:39:31 · 392 阅读 · 0 评论 -
Django 前后台交互注意
from django.http import JsonResponsedef test(request): result = {"status":"错误","data":"","city":"北京"} return return JsonResponse(result)上述代码容易乱码,改成以下中文成功from django.http import HttpRes...原创 2020-03-16 18:10:13 · 163 阅读 · 0 评论 -
__str__ returned non-string (type NoneType)
用户表是Django中核心的表,当这个表类字段中有一个这样的函数 1 2 def__str__(self): returnself.name 在Django用户表设计时候有个字段容易犯这个失误,虽然表字段约束没错 1 name=models.CharField(max_length=30, ...转载 2020-03-16 01:03:59 · 1656 阅读 · 0 评论 -
Django继承AbstractUser新建User Model时出现fields.E304错误
(venv) D:\zz\PycharmProjects\output>python manage.py makemigrationsSystemCheckError: System check identified some issues:ERRORS:auth.User.groups: (fields.E304) Reverse accessor for 'User.group...原创 2020-03-15 22:36:20 · 347 阅读 · 0 评论 -
django 扩容user信息
from django.contrib.auth.models import Userclass Employee(models.Model): user = models.OneToOneField(User, primary_key=True, on_delete=models.CASCADE) department = models.CharField(max_leng...原创 2020-03-15 22:03:51 · 160 阅读 · 0 评论 -
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'system.sysuser', bu
已经在settings.py文件中注册过app仍旧提示没有安装,并且使用makegirations命令时会抛出如下异常。ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'system.sysuser', but app 'system' isn't installed.解决办...原创 2020-03-15 12:15:26 · 693 阅读 · 0 评论 -
django 安装xadmin 替代admin
01-下载源码 安装https://github.com/sshwsfc/xadminInstallXadmin is best installed via PyPI. To install the latest version, run:pip install xadminor Install from github source:pip install git+git:...原创 2020-03-17 23:24:27 · 6125 阅读 · 0 评论 -
ubuntu配置django环境
1、申请云主机,部署ubuntu主机,开放22端口2、系统Ubuntu16.04,系统自带2个版本的python,一个是python2.7,一个是python3.5安装pip工具sudo apt-get install python3-pip安装本地虚拟环境管理工具sudo apt-get install python3-virtualenvpython2 --versio...原创 2020-03-14 15:59:58 · 320 阅读 · 0 评论 -
Python格式化输出,及使用F-Strings报错原因
格式化输出常用语法这里我截取了一部分我个人认为常见的格式化输出语法,除了方法四其他的我均使用过(方法四会报错,原因后面会说到),截取自该链接,大家也可以参考这篇博客,不过我觉得读那么多没用,不会去用也会忘,先熟练本文语法完全够用了,二八定律适用于绝大多数场合。# 方法0, 最原始的方法,类似C语言,不推荐使用name = "Eric" age = 74 '%s is %s.' % ...转载 2020-03-14 15:36:21 · 980 阅读 · 1 评论 -
Django Admin中增加导出Excel功能过程解析
在使用Django Admin时, 对于列表我们有时需要提供数据导出功能, 如下图:增加导出Excel功能在Django Admin中每个模型的Admin类(继承至admin.ModelAdmin)在Django Admin中每个模型的Admin类(继承至admin.ModelAdmin), 我们可以通过actions增加支持的动作, 值为当前类存在的方法名, 例如:.........原创 2020-03-14 15:33:34 · 368 阅读 · 0 评论 -
unbuntu 云主机 远程部署系统
1、安装pip工具sudo apt-get install python3-pipapt install python-pippip install --upgrade pip 貌似必须装这个,有点慢,必须升级,要不然virtualenv不能识别,弄完直接就识别成功2、安装本地虚拟环境管理工具sudo apt-get install python3-virtualenv...原创 2020-03-14 15:28:30 · 163 阅读 · 0 评论 -
将python工程部署到新服务器(对virtualenv工具进行环境迁移)
将python工程部署到新服务器(对virtualenv工具进行环境迁移)# 从开发的电脑上导出 pip list 到 requirements.txt 文件pip freeze > requirements.txt# 另一台新服务器上,安装项目虚拟环境里面的依赖包注意:安装前需再新建虚拟环境python -m venv env_name或 virtualenv --no-si...转载 2020-03-14 15:27:36 · 384 阅读 · 0 评论 -
Centos 7 升级安装python3.7.4
1、安装必须的软件#更新源中包列表yum -y update#先安装扩展源EPEL 才能安装pip 否则会报错yum -y install epel-release//解决ssl问题,否则报错:pip is configured with locations that require TLS/SSL//你只需执行即可,具体解决过程参见:http://www.cnblogs....原创 2020-03-14 15:26:25 · 215 阅读 · 0 评论 -
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
1、django降级,我才发现直接装都到django3.0.4了,真快 建议选择这个,降级最快卸载django: pip uninstall django安装低版本: pip install django==2.1.82、升级SQLitesqlite3 --version安装最新的sqlite3并设置更新python库版本Centos系统自带的sqlite3版本偏低,在...原创 2020-03-14 15:02:44 · 500 阅读 · 0 评论 -
ubuntu16 升级python3.5 到python3.7
1下载镜像国外的慢成狗,幸亏有我大阿里wget http://cdn.npm.taobao.org/dist/python/3.6.5/Python-3.6.5.tgz2、解压tar-xzvf Python-3.7.1.tgz3、预配置mkdir/usr/local/python3config是一个shell脚本,根据平台的特性生成Makefile文件,为下...原创 2020-03-14 09:20:16 · 1166 阅读 · 1 评论 -
Ubuntu16 安装python3.7.1 报错ModuleNotFoundError: No module named '_ctypes'
sudo apt-get install libffi-dev重新安装即可make && make install其他系统yum install libffi-develsudo dnf install libffi-devel原创 2020-03-14 09:14:51 · 598 阅读 · 0 评论 -
利用django开发自己的网站
1、pycharm创建项目,勾选继承全局环境如果勾选 more setting 可以填写template 和新app的名字或者用命令行python manage.py startapp bbs 来创建和上面app一样的效果mysite-mysite#对整个程序进行配置-init#一个空文件,它告诉Python这个目录应该被看做...原创 2020-02-23 19:57:57 · 3574 阅读 · 0 评论 -
You are trying to add a non-nullable field 'user' to event without a default; we can't do that (the
You are trying to add a non-nullable field 'user' to event without a default; we can't do that (the database needs something to populate existing rows).Please select a fix:1) Provide a one-off def...转载 2020-02-23 11:54:14 · 2454 阅读 · 1 评论 -
(1146, "Table 'django.django_session' doesn't exist")
https://blog.youkuaiyun.com/zb0567/article/details/104453634核查原因,发现是django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresp 导致,所以,一路一路查看搞定。。。而这个原因数据库版本太低。。。。...原创 2020-02-23 02:20:29 · 2244 阅读 · 0 评论 -
django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresp
(venv) D:\zz\PycharmProjects\zilv>python manage.py migrateSystem check identified some issues:WARNINGS:?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default' HI...原创 2020-02-23 00:58:07 · 1240 阅读 · 0 评论