简体   繁体   English

Python 与 Django 导入错误与 RegistrationSupplementBase 无法导入名称“ugettext_lazy”

[英]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 Deprecation Timeline [Django-doc]ugettext_lazy将在删除。 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-registrationGitHub 存储库,该项目不再处于活动状态:最新提交是在 2016 年 11 月。您可以尝试更新该项目,但也许最好寻找一个适用的替代包类似的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:无法导入名称“ugettext_lazy” - ImportError : cannot import name 'ugettext_lazy' 导入错误:无法从“django.utils.translation”导入名称“ugettext_lazy” - ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' Django中的ugettext和ugettext_lazy - ugettext and ugettext_lazy in Django 在 Django4.0 中不能使用 Django-rest-auth; ImportError:无法从“django.utils.translation”导入名称“ugettext_lazy” - Can not use Django-rest-auth in Django4.0 ; ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' Python 中的 makemessages 无法识别 ugettext 和 ugettext_lazy 函数 Django - ugettext and ugettext_lazy functions not recognized by makemessages in Python Django Django:在模板中使用ugettext_lazy - Django: Use ugettext_lazy in templates 带有串联字符串的Django ugettext_lazy - Django ugettext_lazy with concatenated strings Django ugettext_lazy和ugettext在表单字段标签中不起作用 - django ugettext_lazy and ugettext not working in form field label 在 Django 项目中在同一个文件中使用 ugettext 和 ugettext_lazy - Use ugettext and ugettext_lazy in the same file in Django project Python/Django:ugettext_lazy 函数如何与运算符 % 完全配合? - Python/Django: how does the ugettext_lazy function exactly work with operator %?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM