Installation

First steps

  1. Install the package using pip:
pip install django-trench

or add it to your requirements file.

  1. Add trench library to INSTALLED_APPS in your app settings file:
INSTALLED_APPS = (
    ...,
    'rest_framework',
    'rest_framework.authtoken',  # In case of implementing Token Based Authentication
    ...,
    'trench',
)

Note

If you’re going to use djoser to handle user authentication make sure you have it installed and included in INSTALLED_APPS. You’ll also need djangorestframework-jwt to support JSON Web Tokens.

Config

urls.py

urlpatterns = [
    ...,
    url(r'^auth/', include('trench.urls')),
]
If you utilise djoser and JWT authentication:
urlpatterns = [
    ...,
    url(r'^auth/', include('trench.urls')), # Base endpoints
    url(r'^auth/', include('djoser.urls')),
    url(r'^auth/', include('trench.urls.djoser')),  # for Token Based Authorization
    url(r'^auth/', include('trench.urls.jwt')), # for django-rest-framework-jwt
    url(r'^auth/', include('trench.urls.simplejwt')), # for djangorestframework-simplejwt
]

settings.py

django-trench supports djangorestframework built-in Token Based Authentication, as well as JSON Web Tokens. You’ll need setup it accordingly:
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        # or / and
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        # or / and
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}

Migrations

Last but not least, run migrations:
$ ./manage.py migrate