环境:windows + python3.9 + pycharm + django3.2.1
安装xadmin :从 https://github.com/sshwsfc/xadmin 直接下载zip的包
pip install 包的地址
进行安装
加入这三个应用
'xadmin',
'crispy_forms',
'reversion',
迁移数据库,开始处理问题:
运行:pip install six
找到 six 文件
复制到django/utils文件夹内
ugettext_lazy has been removed in Django 4.0 57. Please use gettext_lazy instead
ugettext_lazy 已经被django4 移除了,将它改为gettext_lazy
将 ugettext 改为 gettext
因为Django 3.x 已经把django.core.urlresolvers模块的内容迁移至django.urls中
将:
from django.core.urlresolvers import reverse
改为:
from django.urls import reverse
将:
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
将:
from django.forms.forms import pretty_name
改为:
from django.utils import formats, six
将:
from django.contrib.staticfiles.templatetags.staticfiles import static
改为:
from django.templatetags.static import static
on_delete=models.CASCADE
将:
forms.Field.__init__(self, required, widget, label, initial, help_text,
*args, **kwargs)
改为:
forms.Field.__init__(self)
将:
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 方法中 return 为 return login.as_view(**defaults)(request) 与 return logout.as_view(**defaults)(request)
先安装 django-advanced-filters,
将:
from django.db.models.fields import FieldDoesNotExist
改为:
from django.core.exceptions import FieldDoesNotExist
将:
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:
将:
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
将:
from django.contrib.auth.views import password_reset_confirm
改为:
from django.contrib.auth.views import PasswordResetConfirmView
将:
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:
改为:
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:
将:
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