我正在更新一个非常旧的 Django 项目并尝试使用 RegistrationSupplementBase 但在导入时我收到此错误消息:
File "/home/projectmachine/Desktop/project_rebuild/projectname/models.py", line 11, in <module>
from registration.supplements.base import RegistrationSupplementBase
File "/home/projectmachine/.local/share/virtualenvs/projectname-QrYA9Qp-/lib/python3.6/site-packages/registration/supplements/base.py", line 9, in <module>
from django.utils.text import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy'
我不知道哪里出了问题。安装的依赖项似乎存在问题。我正在使用 Django 2.2 和 django-inspectional-registration 0.6.2
这是我导入类的方式:
从 registration.supplements.base 导入 RegistrationSupplementBase
最佳答案
I can't figure out what's wrong. It seems like there is an issue with the dependancies installed. I'm using Django 2.2 with
django-inspectional-registration
0.6.2
该函数已移至 django.utils.translation
模块,因此您可以将其导入:
from <b>django.utils.translation</b> import ugettext_lazy as _
基于Django Deprecation Timeline [Django-doc] , ugettext_lazy
将在 django-4.0 中删除.您可以改用 gettext_lazy
:
from django.utils.translation import <b>gettext_lazy</b> as _
基于GitHub repository of django-inspectional-registration
然而,该项目不再活跃:最新的提交是在 2016 年 11 月。您可以尝试更新该项目,但也许最好寻找一个以类似方式工作的替代包。
关于带有 RegistrationSupplementBase 的 Django 导入错误的 Python 无法导入名称 'ugettext_lazy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57098515/