1

I'm new to Django rest and I'm trying to create a very simple application that allows user to login/sign-up using knox. But as I try to run commands like "python manage.py makmigrations" or any other Django related commands, I get this error:

ImportError: Could not import 'knox.auth.TokenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: cannot import name 'ugettext_lazy' from 'django.utils.trans lation' (C:\Users\user\Desktop\Proj\Server\env\lib\site-packages\django\utils\translation\__init__.py).

Here're parts of my settings.py file that I think are related to knox:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'rest_framework',
'knox',
'corsheaders',

'app',]


AUTH_USER_MODEL = 'app.User'

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication', ),}
Masih Bahmani
  • 153
  • 2
  • 10

2 Answers2

4

After spending hours trying to figure out why this is happening, I realized it's because I'm using Django 4.0!!!!!!

I downgraded to Django 3.2.11 and everything turned out to be ok:)

Masih Bahmani
  • 153
  • 2
  • 10
3

After searching on this problem because I have it too. I installed pip install django-rest-knox and it works for me.

Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
mohammedy
  • 44
  • 4
  • Also make sure to use the latest version from django-rest-knox, because earlier versions didn't worked for me with the latest Django. – Andy Nov 15 '22 at 13:44