我的版本:
python:Python3.6
django:2.2.16
原本准备搭建个站点玩玩,使用的是开源的wagtail,搭建过程中各种错误,前面的就不说了,主要记录下更换数据库时候遇到的坑
官方文档说更换数据库只用修改settings.py和__init__.py即可,可是改完之后报错了,报下面这个错
AttributeError: 'str' object has no attribute 'decode'
解决:
[root@localhost mysite]# cd /usr/local/lib64/python3.6/site-packages/django/db/backends/mysql/
[root@localhost mysql]# ls
base.py client.py compiler.py creation.py features.py __init__.py introspection.py operations.py __pycache__ schema.py validation.py
路径可能不一样,可以find查找一下
需要修改其中的三个文件:base.py、operations.py、schema.py
base.py:注释以下两行
#if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
operations.py:
#if query is not None:
# query = query.decode(errors='replace')
#return query
decode修改为encode
if query is not None:
query = query.encode(errors='replace')
return query
schema.py:
if isinstance(value, str):
#quoted = quoted.decode()
quoted = quoted.encode()
return quoted
一样将decode改为encode
然后就是执行下面三条了
python3.6 manage.py migrate
python3.6 manage.py createsuperuser
python3.6 manage.py runserver 0.0.0.0:8000
我是在虚拟机里面,所以监听0.0.0.0,接着就是访问ip+端口了