1、ImportError: No module named xadmin
方案:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0,os.path.join(BASE_DIR,'extra_apps'))
sys.path.insert(1,os.path.join(BASE_DIR,'apps'))
2、Django中使用了xadmin,跑程序时报错 ImportError: cannot import name 'login'
原因在于xadmin在Django2.1.0以上版本不能运行,原本是使用的Django2.0.5,Django版本更新到了高版本,结果login这里一直报错,最后把Django版本改回去就没问题了!
3、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
4、Settings缺少MIDDLEWARE_CLASSES属性,django2.0把MIDDLEWARE_ClASSES改成MIDDLEWARE
xadminpluginslanguage.py改为:if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:
5、django2.0 forms表单初始化只需要一个参数
model = ModelChoiceField(label=_(u'Target Model'), widget=exwidgets.AdminSelectWidget)
File "D:Envsdjango-xadminlibsite-packagesxadmin-0.6.1-py3.6.eggxadminviewsdashboard.py", line 284, in __init__
forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs)
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)