前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Django项目中xadmin遇到的坑记录

Django项目中xadmin遇到的坑记录

原创
作者头像
墨紫羽墨
发布2021-12-12 19:25:56
9620
发布2021-12-12 19:25:56
举报
文章被收录于专栏:FutureTester

第一次写Django项目,使用xadmin报了一大堆的错误,此次记录一下问题和方法方便下次使用

xadmin下载:

在百度中搜索GitHub,进入官网,然后搜索xadmin即可

1、错误提示:No module named 'django.contrib.staticfiles.templatetags'

解决方法:

  将 from django.contrib.staticfiles.templatetags.staticfiles import static

  替换成:from django.templatetags.static import static

2、错误提示:ModuleNotFoundError: No module named ‘django.core.urlresolvers’

解决方法:

  把原来的 django.core.urlresolvers

  更改为了 django.urls

3、错误提示:ImportError: cannot import name ‘six‘ from ‘django.utils‘

解决方法:

  1.pip3 install six

  2.进入python3.6/site-packages

  3.将six.py 复制到 django/utils即可

4、错误提示:ImportError: cannot import name 'python_2_unicode_compatible'

解决方法:

  方法一:使用django2.2.x版本

      pip install django==2.2.10

  方法二:将 from django.utils.encoding import python_2_unicode_compatible

      改成 from six import python_2_unicode_compatible

5、错误提示: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)

6、错误提示: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

7、错误提示:Python from django.contrib.auth.views import logout ImportError: cannot import name 'logout'

解决方法:

  将 from django.contrib.auth.views import logout

  修改为 from django.contrib.auth.views import LogoutView as logout

8、错误提示:TypeError: __init__() missing 1 required positional argument: 'on_delete'

解决方法:

  关联关系ForeignKey引发的错误,凡是出现关联关系字段的地方全部加上 on_delete=models.CASCADE

9、错误提示:AttributeError: 'Settings' object has no attribute 'MIDDLEWARE_CLASSES'

解决方法:

  将xadmin\plugins\language.py 中的 if settings.LANGUAGESand 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES:

  修改为:if settings.LANGUAGESand 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:

10、错误提示:ImportError: cannot import name 'SKIP_ADMIN_LOG'

解决方法:

  去掉 SKIP_ADMIN_LOG, TMP_STORAGE_CLASS,换成 ImportMixin

  ImportMixin 这个类里写了 skip_admin_log 和 tmp_storage_class 方法

原文地址

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档