Django集成xadmin 错误集锦

Django集成xadmin 错误集锦

环境:windows + python3.9 + pycharm + django3.2.1

安装xadmin :从 https://github.com/sshwsfc/xadmin 直接下载zip的包
pip install 包的地址
进行安装

加入这三个应用
    'xadmin',
    'crispy_forms',
    'reversion',

迁移数据库,开始处理问题:

问题1:ImportError: cannot import name ‘six’ from ‘django.utils’

运行:pip install six
找到 six 文件
复制到django/utils文件夹内

问题2:ImportError: cannot import name ‘ugettext_lazy’ from django.utils.translation’

 ugettext_lazy has been removed in Django 4.0 57. Please use gettext_lazy instead
 ugettext_lazy 已经被django4 移除了,将它改为gettext_lazy

问题3:ImportError: cannot import name ‘ugettext’ from ‘django.utils.translation’

 将 ugettext 改为 gettext

问题4:ModuleNotFoundError: No module named ‘django.core.urlresolvers’

因为Django 3.x 已经把django.core.urlresolvers模块的内容迁移至django.urls中

将:
from django.core.urlresolvers import reverse
改为:
from django.urls import reverse

问题5:ImportError: cannot import name ‘python_2_unicode_compatible’ from ‘django.utils.encoding’

将:
from django.utils.encoding import python_2_unicode_compatible, smart_text
改为:
from django.utils.encoding import smart_text
from six import python_2_unicode_compatible

问题6:ImportError: cannot import name ‘pretty_name’ from ‘django.forms.forms’

将:
from django.forms.forms import pretty_name
改为:
from django.utils import formats, six

问题7:ModuleNotFoundError: No module named ‘django.contrib.staticfiles.templatetags’

将:
from django.contrib.staticfiles.templatetags.staticfiles import static
改为:
from django.templatetags.static import static

问题8:TypeError: init() missing 1 required positional argument: ‘on_delete’

on_delete=models.CASCADE

问题9: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)

问题10:ImportError: cannot import name ‘login’ from ‘django.contrib.auth.views’

将:
from django.contrib.auth.views import login
改为:
from django.contrib.auth.views import LoginView as login
将:
from django.contrib.auth.views import logout
改为:
from django.contrib.auth.views import LogoutView as logout

注释掉
class LoginView(BaseAdminView)class LogoutView(BaseAdminView)get 方法中 defaults 字典的 'current_app': self.admin_site.name,

修改
class LoginView(BaseAdminView)class LogoutView(BaseAdminView)get 方法中 returnreturn login.as_view(**defaults)(request)return logout.as_view(**defaults)(request)


问题11:ImportError: cannot import name ‘FieldDoesNotExist’ from ‘django.db.models.fields’

先安装 django-advanced-filters,

将:
from django.db.models.fields import FieldDoesNotExist
改为:
from django.core.exceptions import FieldDoesNotExist

问题12:ImportError: cannot import name ‘QUERY_TERMS’ from ‘django.db.models.sql.query’

将:
from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS
改为:
from django.db.models.sql.query import LOOKUP_SEP, Query

同文件下,将:
if len(parts) > 1 and parts[-1] in QUERY_TERMS:
改为:
if len(parts) > 1 and parts[-1] in Query:    

问题13:ImportError: cannot import name ‘FieldDoesNotExist’ from ‘django.db.models.fields’

将:
from django.db.models import FieldDoesNotExist, Avg, Max, Min, Count, Sum
改为:
from django.db.models import Avg, Max, Min, Count, Sum
from django.core.exceptions import FieldDoesNotExist

问题14:ImportError: cannot import name ‘password_reset_confirm’ from ‘django.contrib.auth.views’

将:
from django.contrib.auth.views import password_reset_confirm
改为:
from django.contrib.auth.views import PasswordResetConfirmView

问题15: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:

问题16:ImportError: cannot import name ‘DEFAULT_FORMATS’ from ‘import_export.admin’

将:
from import_export.admin import DEFAULT_FORMATS, SKIP_ADMIN_LOG, TMP_STORAGE_CLASS
改为:
from import_export.formats.base_formats import DEFAULT_FORMATS
from import_export.admin import ImportMixin, ImportExportMixinBase

创建数据表部分的问题到此结束:

makemigrations 
migrate
创建数据表



之所以在 django3.2.1 中使用 xadmin 会出现这么多报错,是因为 xadmin 针对 django 进行开发的版本最多到 djang 2,后面 xadmin 成为一个完全的前端框架,对 django 的专门支持不如以前了。

参考网址:https://blog.csdn.net/dangfulin/article/details/116785621

你可能感兴趣的:(django,python)