django-rest-framework Token Authentication With Django Rest Framework ADDING AUTH FUNCTIONALITY


Example

Django REST Framework has some authentication methods already built in, one of them is Token based, so first thing to do is to tell our project we’re going to use rest framework’s authentication. Open settings.py file and add the highlighted line.

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'test_app',
)

As we’ve added a new app to the project, we must synchronize

python manage.py migrate

CREATING A SUPERUSER IN DJANGO

In order to use authentication, we can rely on django users model, so the first thing to do is to create a superuser.

python manage.py createsuperuser