1、django2.0把from django.core.urlresolvers修改成了django.urls
报错如下:
1
2
3
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 8, in <module>
from django.core.urlresolvers import NoReverseMatch, reverse
ModuleNotFoundError: No module named 'django.core.urlresolvers'
|
解决方法:
修改D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py 文件
把from django.core.urlresolvers import NoReverseMatch, reverse 修改为:
1
|
from django.urls import NoReverseMatch, reverse
|
2、django2.0中需要给外键ForeignKey指定on_delete参数
报错如下:
1
2
3
4
5
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 45, in <module>
class Bookmark(models.Model):
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\models.py", line 49, in Bookmark
content_type = models.ForeignKey(ContentType)
TypeError: __init__() missing 1 required positional argument: 'on_delete'
|
解决方法:
把content_type = models.ForeignKey(ContentType)修改为:
1
|
content_type = models.ForeignKey(ContentType,on_delete=models.CASCADE)
|
3、 django2.0 forms表单初始化只需要一个参数
报错如下:
1
2
3
4
|
model = ModelChoiceField(label=_(u'Target Model'), widget=exwidgets.AdminSelectWidget)
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\views\dashboard.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) 修改成:
1
|
forms.Field.__init__(self)
|
4、 导入QUERY_TERMS报错
报错如下:
1
2
3
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\plugins\filters.py", line 10, in <module>
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
ImportError: cannot import name 'QUERY_TERMS'
|
解决方法:
把
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
修改为:
1
2
|
from django.db.models.sql.query import LOOKUP_SEP
from django.db.models.sql.constants import QUERY_TERMS
|
5、Settings缺少MIDDLEWARE_CLASSES属性,django2.0把MIDDLEWARE_ClASSES改成MIDDLEWARE
报错如下:
1
2
3
4
5
|
File "D:\Envs\django-xadmin\lib\site-packages\xadmin-0.6.1-py3.6.egg\xadmin\plugins\language.py", line 24, in <module>
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
File "D:\Envs\django-xadmin\lib\site-packages\django\conf\__init__.py", line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'MIDDLEWARE_CLASSES'
|
把
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_ClASSES:
修改为:
1
|
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:
|
6、 django-formtools导入失败,需要更新django-formtools
报错如下:
1
2
3
|
File "C:\Users\laoyan\Desktop\xadmin-django2\xadmin-django2\demo_app\..\xadmin\plugins\wizard.py", line 12, in <module>
from django.contrib.formtools.wizard.storage import get_storage
ModuleNotFoundError: No module named 'django.contrib.formtools'
|
卸载django-formtools
pip uninstall django-formtools
重新安装新版本的django-formtools
1
|
pip install django-formtools==2.1
|
相关推荐
python3.6环境中django2.0与xadmin0.6结合打造强悍的后台管理页面(一)