其他分享
首页 > 其他分享> > Django2.1.1与xadmin0.6.0遇到的坑

Django2.1.1与xadmin0.6.0遇到的坑

作者:互联网

(1)django2.0把from 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 NoReverseMatch, reverse修改为from django.urls import NoReverseMatch, reverse

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

TypeError: __init__() missing 1 required positional argument: 'on_delete'
把content_type = models.ForeignKey(ContentType)修改为content_type = models.ForeignKey(ContentType,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'
把:
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)提示导入QUERY_TERMS报错

ImportError: cannot import name 'QUERY_TERMS'
在Django2.0版本中把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
但是在Django2.1.1中还没找到答案,所以我决定自己写了一个后台放弃了xadmin...还好自己是个full stack developer...

标签:__,xadmin0.6,遇到,models,MIDDLEWARE,Django2.1,django,import,formtools
来源: https://www.cnblogs.com/meticuloustodo/p/10368208.html