天天看點

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包。