[英]Python with Django Import error with RegistrationSupplementBase cannot import name 'ugettext_lazy'
I'm updating a very old Django project and trying to use RegistrationSupplementBase but when importing I get this error message:我正在更新一个非常旧的 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'
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 2.2 和 django-inspectional-registration 0.6.2
Here is how I am importing the class:这是我导入类的方式:
from registration.supplements.base import 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 2.2 和
django-inspectional-registration
0.6.2
The function has been moved to the django.utils.translation
module, so you can import this with:该函数已移至
django.utils.translation
模块,因此您可以使用以下命令导入:
from
django.utils.translation import ugettext_lazy as _
Based on the Django Deprecation Timeline [Django-doc] , ugettext_lazy
will be removed in django-4.0 .根据Django Deprecation Timeline [Django-doc] ,
ugettext_lazy
将在django-4.0 中删除。 You can use gettext_lazy
instead:您可以改用
gettext_lazy
:
from django.utils.translation import
gettext_lazy as _
Based on theGitHub repository of django-inspectional-registration
however, the project is not active anymore: the latest commit was in november 2016. You can try to update the project, but perhaps it is better to look for an alternative package that works in a similar way.然而,基于
django-inspectional-registration
的GitHub 存储库,该项目不再处于活动状态:最新提交是在 2016 年 11 月。您可以尝试更新该项目,但也许最好寻找一个适用的替代包类似的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.