Django Rest Framework
it’s
The end
Intro
This is the last part of the series. Feel free to go back if you haven’t read the previous part yet. I’ll wait at the same spot, and don’t cry. Oh! don’t forget to grab the code, and let’s get started!!
Outline
Here’s what this part covers:
Adding url patterns to the main app.
Working with the admin page.
Database migrations.
Using bruno to call APIs.
A word about knox.
Adding url patterns to the main app
See this diagram.
Register apps
Add the following lines to settings.py
# settings.py
INSTALLED_APPS = [
‘ django.contrib.admin’,
‘ django.contrib.auth’,
‘ django.contrib.contenttypes’,
‘ django.contrib.sessions’,
‘ django.contrib.messages’,
‘ django.contrib.staticfiles’,
# register app
‘ rest_framework’,
‘ knox’,
‘ dog_house’,
]
Add theses lines for the default authentication classes. Note that we can override the default authentication classes for each API.
# settings.py
REST_FRAMEWORK = {
‘ DEFAULT_AUTHENTICATION_CLASSES’: (‘ knox.auth.TokenAuthentication’,),
}
Database migrations
Run the following command:
poetry run python manage.py makemigrations
poetry run python manage.py migrate
Working with the admin page
Here’s a step to work with admin page.
Using Bruno to interact with Django
We will use Bruno to make API calls.
Make sure that the server is running.
Go to the login folder in Bruno, open the file named Login.
Add the correct credentials and hit CTRL + Enter.
Copy the value of the token field of the response JSON.
Put the token with in the Headers when you perform a request.
That’s about it.
A word about Django Rest Knox
I omit the detail about Django Rest Knox. If you are interested you, check it out.
The end
I hope you find my series useful. Feedback is welcome. Thank you for your attention.