Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 22, 2022 06:06 pm GMT

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 djangopip install djangopip install djangorestframework

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

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',]

Now lets start our app

django manage.py runserver

You will get this output

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

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


Original Link: https://dev.to/siddharth1704/django-with-rest-tutorial-1-5g30

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To