xadmin 因为版本问题的错误

针对django 2.0 xadmin 错误集锦

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

解决方法:将from django.core.urlresolvers import NoReverseMatch, reverse

                改成

                  from django.urls import NoReverseMatch, reverse

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

解决方法:将user = models.ForeignKey(AUTH_USER_MODEL, verbose_name=_(u"user"))

    改成

                      user = models.ForeignKey(AUTH_USER_MODEL, verbose_name=_(u"user"), on_delete=models.CASCADE)

        即在外键值的后面加上 on_delete=models.CASCADE

3.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,*args, **kwargs)

4.ImportError: cannot import name 'QUERY_TERMS'

解决方法:将from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS

改成

from django.db.models.sql.query import LOOKUP_SEP

from django.db.models.sql.constants import QUERY_TERMS

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

解决方法:将if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:

改成

if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:

6.

django.db.utils.DataError: (1406, "Data too long for column 'gender' at row 1")

原因:

gender = models.CharField('性别',max_length=30,choices=(('male','男'),('female','女')),default='female')

可以看到设置的字符长度是5,可是female有6个字节,所以修改max_length=7 

注:必须重新生成数据库

python manage.py makemigrations 

python manage.py migrate

7.init() got an unexpected keyword argument 'current_app' 

解决方法:这里面说是要激活中间件必须给他添加一个中间件class ,即MIDDLEWARE_CLASS

              先把MIDDLEWARE

改成MIDDLEWARE_CLASS

8.AttributeError: 'WSGIRequest' object has no attribute 'user'

解决方法:MIDDLEWARE_CLASS = [

    'django.middleware.security.SecurityMiddleware',    1

    'django.contrib.sessions.middleware.SessionMiddleware',    2

    'django.middleware.common.CommonMiddleware',  3

    'django.middleware.csrf.CsrfViewMiddleware',  4

    'django.contrib.auth.middleware.AuthenticationMiddleware',5

    'django.contrib.messages.middleware.MessageMiddleware',6

    'django.middleware.clickjacking.XFrameOptionsMiddleware',7

]

还未解决,有大佬帮忙吗?


------------------------------------------------------------------------------------------------------------------------------------

上面那个问题解决很麻烦,我估计解决不了,算了,接下来可以看我下一篇文章。直接django2.0版本的

你可能感兴趣的:(xadmin 因为版本问题的错误)