5

I'm updating a very old Django project and trying to use RegistrationSupplementBase but when importing, I got the error below:

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

Here is how I am importing the class:

from registration.supplements.base import RegistrationSupplementBase

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
La Fon
  • 145
  • 1
  • 1
  • 9
  • These have been moved to `django.utils.translation`. But anyway these are depraceted. You should replace it with `from django.utils.translation import gettext_lazy as _`. – Willem Van Onsem Jul 18 '19 at 16:05
  • In this case, the error is coming from django-inspectional-registration. It looks like It has [not been updated](https://github.com/lambdalisue/django-inspectional-registration) for several years, so it will not support recent versions of Django. You could try forking the code and making the change the Willem suggests, but I suspect there will be other changes required to make it work with Django 2.2. – Alasdair Jul 18 '19 at 16:08

1 Answers1

22

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

The function has been moved to the django.utils.translation module, so you can import this with:

from django.utils.translation import ugettext_lazy as _

Based on the Django Deprecation Timeline [Django-doc], ugettext_lazy will be removed in . You can use gettext_lazy instead:

from django.utils.translation import gettext_lazy as _

Based on the GitHub 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.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555