DEV Community

Cover image for Django with Rest Tutorial -1
Siddharth
Siddharth

Posted on

Django with Rest Tutorial -1

Hey everyone so this is my first blog on Dev. So I was learning Django and came across Django rest Frame work. I know that there are aloooooooooot of tutorials on Django Rest on YouTube but no one talks much in depth about the whole concept of serialization and desrialization and in this tutorial series i will be taking about it from scratch and will be creating small applications to make you understand Django Rest Frame work in easy way.
So lets get started
Alt text
Pre-requisites:

  • Python(Basics)

Tools & Dependcies:

  • VsCode

  • Postman

  • Chrome(or any other latest browser)

  • Python 3 or greater

  • Django

  • Django rest-framework

Installation:

pip install django
pip install django
pip install djangorestframework
Enter fullscreen mode Exit fullscreen mode

Creating a web-server/django app

So if you are coming from a background of nodejs where we create webserver.The same is achieved here by creating an app/project.The simple command to create a django project is:
django-admin startproject <projectname>
Once you run this command a project will be created.But before you do so i prefer to create a seprate virtual environment using venv package for your web applications so at anytime you want to host your appication you can easily get its dependecies.

So let's start with basic theory first.
What is an API?
API is basically like an waiter that takes order from the frontend and requests the data from backend and delivers back to the frontend.
Alt text
Ps:You don't need to tip the api.
So moving on to the smaller question What is a rest api Basically REST is a set of architectural constraints that is used in developing an api that will be taking more about as we start to develop our api.

Creating our application

Run the following commands

 django makeproject harrypotter
 django startapp grffyindorr
Enter fullscreen mode Exit fullscreen mode

So first command creates our project called harrypoter and then we have made an app grffyindoor.
So what is an app basically app helps in managing things separately when we work in a team for particular component
For eg: Instagram has feature of chat so we can create an app in insta as chat and all the people working on it can edit that app without worrying about other things

Now lets move to installed apps an
Add 'rest_framework, grffyindorr' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
    ...
    'rest_framework',
    'grffyindorr',
]
Enter fullscreen mode Exit fullscreen mode

Now lets start our app

django manage.py runserver
Enter fullscreen mode Exit fullscreen mode

You will get this output

System check identified no issues (0 silenced).
December 22, 2022 - 17:16:09
Django version 4.1.3, using settings 'rest.settings'
Starting development server at http://127.0.0.1:8000/
Enter fullscreen mode Exit fullscreen mode

Open that url on your server and you will see a rocket launching on it
Congragulations ๐ŸŽ‰๐ŸŽ‰ You have succesfully created an application in django and ran it
Alt text
Stay tuned for next part where will create our database and start writing our first api

Top comments (2)

Collapse
 
aayush_giri profile image
Aayush Giri

Quite impressive man!!

Collapse
 
surajv profile image
Surajv

Insightful article. Looking forward to more such tutorials!