Xadmin - 转到Django2.0以上的报错信息 ———

2019-07-15  本文已影响0人  一只小青蛙

错误(1):Django2.1.1版本将django.core.urlresolvers改为了django.urls

异常信息:

ModuleNotFoundError: No module named  'django.core.urlresolvers'

解决方案:

修改site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py
将
from django.core.urlresolvers import XXX
修改为
from django.urls import XXX

(2)django2.1.1中需要给外键指定on_delete参数

异常信息:

TypeError: __init__() missing 1 required positional argument: 'on_delete'

解决方案:

把ForeignKey模块
models.ForeignKey(User)
修改为
models.ForeignKey(User,on_delete=models.CASCADE)

(3)django2.1.1的 forms表单初始化只一个参数

异常信息:

TypeError: __init__() takes 1 positional argument but 6 were given

解决方案:

把
forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs) 
修改为
forms.Field.__init__(self) 

(4)Settings缺少MIDDLEWARE_CLASSES属性,django2.1.1把MIDDLEWARE_ClASSES改成>MIDDLEWARE

异常信息:

AttributeError: 'Settings' object has no attribute 'MIDDLEWARE_CLASSES'

解决方案:

将xadmin\plugins\language.py 中的:
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_ClASSES:
改成:
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:

(5)django-formtools导入失败,更新django-formtools版本就好了

异常信息:

ModuleNotFoundError: No module named 'django.contrib.formtools'

解决方案:

pip uninstall django-formtools
pip install django-formtools==2.1

(6)导入错误ImportError: cannot import name 'login' from 'django.contrib.auth.views'

异常信息:

ImportError: cannot import name 'login' from 'django.contrib.auth.views' 

解决办法:

将 website.py 中的:
from django.contrib.auth.views import login
from django.contrib.auth.views import logout
修改为:
from django.contrib.auth import authenticate, login, logout

(7)导入错误ImportError: cannot import name 'QUERY_TERMS' from 'django.db.models.sql.query'

异常信息:

ImportError: cannot import name 'QUERY_TERMS' from 'django.db.models.sql.query'

解决办法:

将xadmin\plugins\filters.py文件中的
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
修改为
from django.db.models.sql.query import LOOKUP_SEP, Query

(8)导入错误password_reset_confirm

异常信息:

ImportError: cannot import name 'password_reset_confirm' from 'django.contrib.auth.views'

解决办法:

将xadmin\plugins\passwords.py中的:
from django.contrib.auth.views import password_reset_confirm
修改为:
from django.contrib.auth.views import PasswordResetConfirmView

另外,Django数据同步过程中遇到的问题:

1、错误信息

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

解决办法:

C:\Python37\Lib\site-packages\django\db\backends\mysql(python安装目录)打开base.py,注释掉以下内容:

      if version < (1, 3, 13):
          raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

2、错误信息:

File "C:\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query

query = query.decode(errors='replace')

AttributeError: 'str' object has no attribute 'decode'

解决办法:打开此文件把146行的decode修改为encode




上一篇下一篇

猜你喜欢

热点阅读