I imported from rest_auth.views import LoginView
and I am trying to implement login API I never import ugettext_lazy
directly.
from rest_auth.views import LoginView
from django.contrib.auth import authenticate, login, logout
from .serializers import LoginUserSerializer
class Login(LoginView):
def post(self, request, *args, **kwargs):
serializer = LoginUserSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.validated_data['user']
login(request, user)
return super().post(request, format=None)
I received this Error:
File "filePath\ProjectName\app1\urls.py", line 4, in <module> from .login
import Login
File "filePath\ProjectName\app1\login.py", line 1, in <module> from
rest_auth.views import LoginView
File "\myenv\lib\site-packages\rest_auth\views.py", line 9, in <module>
from django.utils.translation import ugettext_lazy as _ ImportError:
cannot import name 'ugettext_lazy' from 'django.utils.translation' (\myenv\lib\site-packages\django\utils\translation\__init__.py)
I read the other answers and most of the answers suggested downgrading from Django version 4 to 3.
Are there any other ways to fix this problem or any other suggestions to implement login API?
pip
is installing django 4
by default, and django-user-session
doesn't seems to be compatible with Django 4.0
which does not have ugettext_lazy
You can fix the issue by downgrading the version of django
to 3.2 until 4.0 is properly supported.
pip install django==3.2
This is a temporary workaround for the issue.
ugettext_lazy has been removed in Django 4. I am used gettext_lazy instead: from django.utils.translation import gettext_lazy as _
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.