問題一 reload(sys)報(bào)錯(cuò)
解決方法:
import importlib
importlib.reload(sys)
問題二 django-simple-serializer庫安裝失敗
下載django-simple-serializer-2.0.7.tar.gz,解壓后,修改setup.py文件:
import importlib
importlib.reload(sys)
LONG_DESCRIPTION =open('README.rst','r', encoding='UTF-8').read()
運(yùn)行python setup.py install,成功。
問題三 數(shù)據(jù)庫報(bào)錯(cuò)django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
注釋掉檢測(cè)數(shù)據(jù)庫版本的代碼(packages/django/db/backends/mysql/base.py", line 36, in <module>):
# if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
問題四 運(yùn)行報(bào)錯(cuò)AttributeError: 'str' object has no attribute 'decode'
解決辦法:打開"\lib\site-packages\django\db\backends\mysql\operations.py"文件把146行的decode修改為encode即可。
if query is not None:
query = query.decode(errors='replace')
問題五 django-simple-serializer庫,使用報(bào)錯(cuò)'AutoField' object has no attribute 'rel'
pro_id_name = serializer(projects, include_attr=("id", "name", "project_abbr", "latest_ver"))
問題起因:在django1.9及之后版本,autoField字段類型使用remote_field而不是ref,需要做一下兼容。
解決方法:https://github.com/bluedazzle/django-simple-serializer/issues/8
修改django_simple_serializer-2.0.7-py3.6.egg包里的Serializer.py文件,函數(shù)data_inspect里增加判斷:
for field in concrete_model._meta.local_fields:
# 檢查 field 是否存在 rel 這個(gè)屬性,為'AutoField' object has no attribute 'rel'錯(cuò)誤填坑
if hasattr(field, 'rel'):
if field.rel is None:
if self.check_attr(field.name) and hasattr(data, field.name):
obj_dict[field.name] = self.data_inspect(getattr(data, field.name))
else:
if self.check_attr(field.name) and self.foreign:
obj_dict[field.name] = self.data_inspect(getattr(data, field.name))
else:
if self.check_attr(field.name) and hasattr(data, field.name):
obj_dict[field.name] = self.data_inspect(getattr(data, field.name))