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 pre­vi­ous part yet. I’ll wait at the same spot, and don’t cry. Oh! don’t for­get to grab the code, and let’s get started!!

Outline

Here’s what this part cov­ers:

  1. Adding url pat­terns to the main app.

  2. Work­ing with the admin page.

  3. Data­base migra­tions.

  4. Using bruno to call APIs.

  5. A word about knox.

Adding url patterns to the main app

See this dia­gram.

Register apps

Add the fol­low­ing lines to set­tings.py

# set­tings.py

INSTALLED_APPS = [
   django.con­trib.admin’,
   django.con­trib.auth’,
   django.con­trib.con­tent­types’,
   django.con­trib.ses­sions’,
   django.con­trib.mes­sages’,
   django.con­trib.sta­t­ic­files’,

    # reg­is­ter app
   rest_frame­work’,
   knox’,
   dog_house’,
]

Add the­ses lines for the default authen­ti­ca­tion classes. Note that we can over­ride the default authen­ti­ca­tion classes for each API.

# set­tings.py

REST_FRAME­WORK = {
   DEFAULT_AUTHEN­TI­CA­TION_CLASSES’: (knox.auth.Token­Authen­ti­ca­tion’,),
}

Database migrations

Run the fol­low­ing com­mand:

poetry run python man­age.py makem­i­gra­tions
poetry run python man­age.py migrate

Working with the admin page

Here’s a step to work with admin page.

  1. Reg­is­ter a model to the admin page.

  2. Cre­ate admin user.

  3. Start the devel­op­ment user

  4. Add data of Color via admin page.

Using Bruno to interact with Django

We will use Bruno to make API calls.
Make sure that the server is run­ning.
Go to the login folder in Bruno, open the file named Login.
Add the cor­rect cre­den­tials and hit CTRL + Enter.
Copy the value of the token field of the response JSON.
Put the token with in the Head­ers when you per­form a request.
That’s about it.

A word about Django Rest Knox

I omit the detail about Django Rest Knox. If you are inter­ested you, check it out.

The end

I hope you find my series use­ful. Feed­back is wel­come. Thank you for your atten­tion.