I installed djangorestframework as shown below:
pip install djangorestframework -jwt
Then, I used rest_framework_jwt.views
as shown below:
from rest_framework_jwt.views import (
obtain_jwt_token,
refresh_jwt_token,
verify_jwt_token
)
...
path('auth-jwt/', obtain_jwt_token),
path('auth-jwt-refresh/',refresh_jwt_token),
path('auth-jwt-verify/', verify_jwt_token),
...
But, I got the error below:
ImportError: cannot import name 'ugettext' from 'django.utils.translation'
So, how can I solve the error?
from .serializers import (
File "*\lib\site-packages\rest_framework_jwt\serializers.py", line 7, in
from django.utils.translation import ugettext as _
ImportError: cannot import name 'ugettext' from 'django.utils.translation' (c:\users\dell\downloads\djangoEnvs\djangoEnv\lib\site-packages\django\utils\translation_init_.py)
There are two ways of resolving above issues:
Way 1: (Not recommended Approach)
Steps:
Open the last file in traceback (<path showing in your IDE>\lib\site-packages\rest_framework_jwt\serializers.py) :
In this file, replace ugettext with --> gettext
Enjoy coding!!!! :)
before replace:
from django.utils.translation import ugettext as _
after replace:
from django.utils.translation import gettext as _
Way2 : (Recommended Approach)
Steps are:
import django
from django.utils.translation import gettext
django.utils.translation.ugettext = gettext
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With