带有 RegistrationSupplementBase 的 Django 导入错误的 Python 无法导入名称 'ugettext_lazy'

标签 python django python-3.6 django-registration

我正在更新一个非常旧的 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 将在 中删除.您可以改用 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/

相关文章:

python-3.x - 没有名为 '__main__.demo' 的模块; '__main__' 不是python3包

Python 类方法 : what's the difference between a member of an instance and a member of the class?

python - 如何从 npy.gz 文件中恢复一个 numpy 数组

python - 如何为 SQL 语句创建单元测试?

python - 使用上限和下限向量创建新变量

django - 如何在 Django 模板中获取 Camelcase 类字段

python - 在 Django 3 中使用 Bootstrap 时遇到问题

python - 如何在调用 render() 时获取 Django 模板错误的文件名和行号?

pandas - 需要向 pd.df 添加一列,其中包含函数中的值

pandas - 连续检查缺失的日期时间值的问题