Installation¶
First steps¶
Install the package using pip:
pip install django-trench
or add it to your requirements file.
Add
trench
library toINSTALLED_APPS
in yoursettings.py
file:
INSTALLED_APPS = (
...,
'rest_framework',
'rest_framework.authtoken', # In case of implementing Token Based Authentication
...,
'trench',
)
Setup¶
With JWT authentication¶
Include Django Trench’s URLs to your application:
urlpatterns = [
...,
url(r'^auth/', include('trench.urls')),
url(r'^auth/', include('trench.urls.jwt')),
]
Adjust your
settings.py
file like so:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}
With token authentication¶
Include Django Trench’s URLs to your application:
urlpatterns = [
...,
url(r'^auth/', include('trench.urls')),
url(r'^auth/', include('trench.urls.authtoken')),
]
Adjust your
settings.py
file like so:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
}
Add
rest_framework.authtoken
to yourINSTALLED_APPS
:
INSTALLED_APPS = (
...,
'rest_framework.authtoken',
)
Migrations¶
Last but not least, run migrations:
python manage.py migrate