1、django2.0把from django.core.urlresolvers修改成了django.urls
报错如下:
1 2 3 | |
解决方法:
修改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 | |
2、django2.0中需要给外键ForeignKey指定on_delete参数
报错如下:
1 2 3 4 5 | |
解决方法:
把content_type = models.ForeignKey(ContentType)修改为:
1 | |
3、 django2.0 forms表单初始化只需要一个参数
报错如下:
1 2 3 4 | |
解决方法:
把forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs) 修改成:
1 | |
4、 导入QUERY_TERMS报错
报错如下:
1 2 3 | |
解决方法:
把from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
修改为:
1 2 | |
5、Settings缺少MIDDLEWARE_CLASSES属性,django2.0把MIDDLEWARE_ClASSES改成MIDDLEWARE
报错如下:
1 2 3 4 5 | |
把if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_ClASSES:
修改为:
1 | |
6、 django-formtools导入失败,需要更新django-formtools
报错如下:
1 2 3 | |
1)卸载django-formtools
2)pip uninstall django-formtools
3)重新安装新版本的django-formtools
1 | |
7、ImportError: cannot import name 'login' :
出现这个错误应该是一开始就安装了django2.1, 该版本还不能完全兼容xadmin2.0, 解决方法是降级为django2.0版本
----------------------------------------------------------------------------------------------------------------------
1、TypeError at /xadmin/
login() got an unexpected keyword argument 'current_app'错误
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/views/website.py in get, line 66
解决方案:根据提示进入website,注释61行 #'current_app': self.admin_site.name,
2、AttributeError at /xadmin/
'Media' object has no attribute 'add_css'
Request Method: GET
Request URL: http://localhost:8000/xadmin/
Django Version: 2.0.1
Exception Type: AttributeError
Exception Value:
'Media' object has no attribute 'add_css'
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/util.py in vendor, line 94
解决方案:
将util.py 中的86行 def vendor(*tags):方法体改为:
css = {'screen': []}
js = []
for tag in tags:
file_type = tag.split('.')[-1]
files = xstatic(tag)
if file_type == 'js':
js.extend(files)
elif file_type == 'css':
css['screen'] += files
return Media(css=css, js=js)
3、AttributeError at /xadmin/xadmin/log/
'DateTimeField' object has no attribute 'rel'
Request Method: GET
Request URL: http://localhost:8000/xadmin/xadmin/log/
Django Version: 2.0.1
Exception Type: AttributeError
Exception Value:
'DateTimeField' object has no attribute 'rel'
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/views/list.py in get_list_queryset, line 228
修改 views/list.py 中228行
if isinstance(field.rel, models.ManyToOneRel):
related_fields.append(field_name)
修改为
if isinstance(field.remote_field, models.ManyToOneRel):
related_fields.append(field_name)
后面继续报这个“rel”的错误,解决方法参考3,根据 Exception Location 提示 找到Xadmin报错行,将 field.rel 修改为 field.remote_field
原文:https://blog.csdn.net/GoAheadNeverTurnBack/article/details/81433629
--------------------------------------------------------------------------------------------------------------------
1:in include 'provide the namespace argument to include() instead
描述:在最外层的urls.py 添加项目的urls后报错,错误显示:in include 'provide the namespace argument to include() instead."
解决方案:修改:url(r'admin/',include(admin.site.urls)) 为 url(r'admin/',admin.site.urls)
2:Specifying a namespace in include() without providing an app_name
描述:在最外层的urls.py 添加项目的urls后报错,错误显示:Specifying a namespace in include() without providing an app_name。
解决方案:在 app_name 目录下的urls.py 文件中rlpatterns前面加上app_name='[app_name]',其中app_name 为项目名称。
3:no module named django.core.urlresolvers
描述:import django.core.urlresolvers 时报错,错误显示no module named django.core.urlresolvers
解决方案:将django.core.urlresolvers 修改为 django.urls即可。
原因就是:django2.0 把原来的 django.core.urlresolvers 包 更改为了 django.urls包。