1. django2.1.5把from django.core.urlresolvers修改成了django.urls
- 异常信息:
ModuleNotFoundError: No module named 'django.core.urlresolvers'
- 解决方案
把xadmin下所有的文件里包含此头的都按下面修改
from django.core.urlresolvers import NoReverseMatch, reverse
修改为:
from django.urls import NoReverseMatch, reverse
2. django2.1.5中需要给外键指定on_delete参数
- 异常信息:
TypeError: __init__() missing 1 required positional argument: 'on_delete'
- 解决方案
所有models.py文件的ForyeignKey中添加on_delete,如下
content_type = models.ForeignKey(ContentType)
修改为:
content_type = models.ForeignKey(ContentType,on_delete=models.CASCADE)
3. django2.1.5的 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.5把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'
- 解决方案
pip3 install django-formtools==2.1
6. 提示导入QUERY_TERMS报错
- 异常信息:
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, Query
本人的经验分享,希望可以帮助到你们,如何不对的地方,可以评论留言,帮我指正一下,如果帮助了你,请给我点个赞吧