翼度科技»论坛 编程开发 python 查看内容

Django3.2使用xadmin2遇到的问题

3

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
使用xadmin2遇到的问题&解决

环境配置:

使用的模块版本:

关联的包
  1. Django               3.2.15
  2. mysqlclient          2.2.4
  3. xadmin               2.0.1
  4. django-crispy-forms >= 1.6.0
  5. django-import-export >= 0.5.1
  6. django-reversion >= 2.0.0
  7. django-formtools == 2.1
  8. future == 0.15.2
  9. httplib2 == 0.9.2
  10. six == 1.10.0
复制代码
注意:

你需要安装的有:
Django=3.2.15
mysqlclient
xadmin
其中:xadmin我使用https方式安装的
  1. pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2
复制代码
xadmin下载链接:
https://github.com/sshwsfc/xadmin/tree/django2
使用:只需要其中的xadmin文件夹,放入项目中使用
问题&解决

问题1、ImportError: cannot import name 'six' from 'django.utils'

解决:在site-packages目录中找到six.py文件,将其复制到django/utils目录下。
问题2、ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\xadmin\models.py", line 11, in <module>
  2.       from django.utils.encoding import python_2_unicode_compatible, smart_text
  3. ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
复制代码

解决:将from django.utils.encoding import python_2_unicode_compatible, smart_text
注释掉并改为:
  1. from django.utils.encoding import smart_text
  2. from six import python_2_unicode_compatible
复制代码
问题3、ImportError: cannot import name 'pretty_name' from 'django.forms.forms'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\xadmin\utils.py", line 7, in <module>
  2.       from django.forms.forms import pretty_name
  3. ImportError: cannot import name 'pretty_name' from 'django.forms.forms'
复制代码

解决:将 from django.forms.forms import pretty_name
注释掉并改为:
  1. from django.utils import formats, six
复制代码
问题4、ModuleNotFoundError: No module named 'django.contrib.staticfiles.templatetags'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\xadmin\utils.py", line 25, in <module>
  2.     from django.contrib.staticfiles.templatetags.staticfiles import static
  3. ModuleNotFoundError: No module named 'django.contrib.staticfiles.templatetags'
复制代码

解决:将25行注释掉并改为:
  1. from django.templatetags.static import static
复制代码
问题5、ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\reversion\revisions.py", line 16, in <module>
  2.     from django.utils.encoding import force_text, python_2_unicode_compatible
  3. ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
复制代码

解决:注释掉并改为:
  1. from django.utils.encoding import force_text
  2. from six import python_2_unicode_compatible
复制代码
问题6、ModuleNotFoundError: No module named 'django.core.urlresolvers'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\reversion\admin.py", line 13, in <module>
  2.     from django.core.urlresolvers import reverse
  3. ModuleNotFoundError: No module named 'django.core.urlresolvers'
复制代码

解决:注释掉并改为:
from django.urls import reverse
问题7、ImportError: cannot import name 'BoundField' from 'django.forms.forms'
  1. File "D:\Python310\.virtualenv\Wuwuchong\Lib\site-packages\crispy_forms\utils.py", line 9, in <module>
  2.     from django.forms.forms import BoundField
  3. ImportError: cannot import name 'BoundField' from 'django.forms.forms'
复制代码

解决:Django新版本BoundField位置移动了。注释掉并改为:
from django.forms.boundfield import BoundField
问题8、ImportError: cannot import name 'memoize' from 'django.utils.functional'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\crispy_forms\compatibility.py", line 26, in <module>
  2.     from django.utils.functional import memoize
  3. ImportError: cannot import name 'memoize' from 'django.utils.functional'
复制代码

解决:这个问题我没有找到解决办法,不过从前面看只要24行没有报错就不会走到这里来。
百度一下,发现在Django 3.2中,django.utils.lru_cache.lru_cache模块已经被移除,因为Django 3.2中不再使用LRU缓存,而是改用内置的标准库中的functools.lru_cache。
将24行注释掉并改为:
  1. from functools import lru_cache
复制代码
问题9、ModuleNotFoundError: No module named 'django.core.urlresolvers'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\crispy_forms\helper.py", line 4, in <module>
  2.     from django.core.urlresolvers import reverse, NoReverseMatch
  3. ModuleNotFoundError: No module named 'django.core.urlresolvers'
复制代码

解决:Django 3.x 版本reverse位置移动了,注释掉并改为:
  1. from django.urls import reverse, NoReverseMatch
复制代码
问题10、ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\xadmin\plugins\filters.py", line 9, in <module>
  2.     from django.db.models.fields import FieldDoesNotExist
  3. ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields'
复制代码

解决:注释掉并改为:
  1. from django.core.exceptions import FieldDoesNotExist
复制代码
问题11、ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\xadmin\plugins\aggregation.py", line 1, in <module>
  2.     from django.db.models import FieldDoesNotExist, Avg, Max, Min, Count, Sum
  3. ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models'
复制代码

解决:注释掉并改为:
  1. from django.core.exceptions import FieldDoesNotExist
  2. from django.db.models import Avg, Max, Min, Count, Sum
复制代码
问题12、ModuleNotFoundError: No module named 'django.core.urlresolvers'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\import_export\admin.py", line 16, in <module>
  2.     from django.core.urlresolvers import reverse
  3. ModuleNotFoundError: No module named 'django.core.urlresolvers'
复制代码

解决:同问题9,注释掉并改为:
  1. from django.urls import reverse
复制代码
问题13、ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\import_export\resources.py", line 15, in <module>
  2.     from django.db.models.fields import FieldDoesNotExist
  3. ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields'
复制代码

解决:同问题10,注释掉并改为:
  1. from django.core.exceptions import FieldDoesNotExist
复制代码
问题14、ImportError raised when trying to load 'crispy_forms.templatetags.crispy_forms_utils': cannot import name 'allow_lazy' from 'django.utils.functional'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\django\template\backends\django.py", line 123, in get_package_libraries
  2.     raise InvalidTemplateLibrary(
  3. django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'crispy_forms.templatetags.crispy_forms_utils': cannot import name 'allow_lazy' from 'django.utils.functional'
复制代码
解决1:需要修改site-packages\crispy_forms\templatetags\crispy_forms_utils.py文件第6行

修改为:
  1. from django.utils.functional import keep_lazy
复制代码
解决2:同一个文件下,第20行,导入错误问题

修改为:
  1. remove_spaces = keep_lazy(remove_spaces, text_type)
复制代码
问题15、TypeError: WidgetTypeSelect.render() got an unexpected keyword argument 'renderer'
  1. File "D:\Python310\.virtualenv\Wuwuchong\lib\site-packages\django\forms\boundfield.py", line 93, in as_widget
  2.     return widget.render(
  3. TypeError: WidgetTypeSelect.render() got an unexpected keyword argument 'renderer'
复制代码
问题发生原因:进入xadmin后台,点击右上角增加用户小组件时,会报错
解决:查看虚拟环境下:Lib\site-packages\xadmin\views\dashboard.py,把97行注释掉即可,如下:


来源:https://www.cnblogs.com/JulyCancer/p/18194163
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具