django 2.0安装xadmin 错误集锦
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' |
1)卸载django-formtools
2)pip uninstall django-formtools
3)重新安装新版本的django-formtools
1 |
pip install django-formtools==2.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包。
- Django2.1集成xadmin管理后台所遇到的错误集锦(填坑)
- Python3.6+Django2.0安装Xadmin(windows)
- Django_xadmin_应用外键搜索功能错误
- Django-pip安装xadmin遇到的问题
- django使用xadmin安装和使用
- AIX安装RAC错误集锦(6)---网卡配置故障
- python3安装 xadmin错误:"UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 3444"(转)
- Centos系统上安装php遇到的错误解决方法集锦
- 第四百节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署CentOS6.5安装python3.5.1
- ADODB.Connection 错误 '800a0e7a' 未找到提供程序。该程序可能未正确安装。解决办法集锦
- AIX 安装 RAC 错误集锦(7)--- CRS清理
- AIX 安装 RAC 错误集锦(7)--- CRS清理
- 安装node-sass时,遇到的错误MSBUILD: error MSB3428 Visual C++ VCBuild.exe 1) .NET Framework 2.0 SDK Microsoft
- 在win10+anaconda的环境基础上,安装django遇到的错误django-admin.py
- Django笔记 pillow安装错误
- 用命令行安装xadmin出现django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
- Django2集成xadmin详解-1-安装Django和xadmin
- ASPNET-.NETFramework 2.0安装或卸载错误.
- Django-两种安装xadmin的方法及主要配置方法和常用字段类型
- Django-Xadmin的安装和应用