Creating Python APIs - The Django REST framework. Adding the API to an existing app.[10/n]

Now that you have learned how to create a Python API using the Django REST Framework from scratch, let's now use it on an existing project.

We'll use a to-do app that is created using the Django web framework. You can find the link to the code here. You can fork the code from there and use it to follow along with me.

image.png

As you can see the app already had the folders todo and todowoo folders in it. We add the api folder by using the command

python manage.py startapp api

also make sure you have the Django REST Framework by using the command

pip3 install djangorestframework

Now that we've added certain new things, let's add it to the settings.py of our main project todowoo

Add 'api', 'restframework', as shown below. (todo would already be present)

image.png

After we've done this, let's add the api urls in urls.py

We'll have to create new urls.py for that in the api folder.

Once we're done creating the file, we can go back to adding the following path to the urls.py of our todowoo folder.

image.png

What it basically means is that every url for api is to be fetched will end in "/api" and we will be including in the urls.py for the api folder.

We'll be adding the urls in the next article. Stay tuned for that.

Hope you enjoyed this post! If you happen to like it, feel free to share. You can also follow me on Twitter on my coding journey.

 
Share this