Installation
Requirements
Knox depends on pythons internal library hashlib
to provide bindings to OpenSSL
or uses
an internal implementation of hashing algorithms for token generation.
Installing Knox
Knox should be installed with pip
pip install django-rest-knox
Setup knox
- Add
rest_framework
andknox
to yourINSTALLED_APPS
, removerest_framework.authtoken
if you were using it.
INSTALLED_APPS = (
...
'rest_framework',
'knox',
...
)
- Make knox's TokenAuthentication your default authentication class for django-rest-framework:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication',),
...
}
-
Add the knox url patterns to your project.
-
If you set TokenAuthentication as the only default authentication class on the second step, override knox's LoginView to accept another authentication method and use it instead of knox's default login view.
-
Apply the migrations for the models.
python manage.py migrate