DEV Community

Sami Ullah Saleem
Sami Ullah Saleem

Posted on

Build a Rest API with Django

  • Install Django using command pip install django
  • Create a project using command django-admin startproject <projectname>

Image description

  • Move to your project directory like mine is api
  • Now, it's time to create an app. We can have multiple apps in single project
  • The command is python manage.py startapp Bookapi

Image description

  • Don't forget to write your app name under installed_apps in settings.py file of your project folder
  • Now go to BookApi directory and there click models.py

Image description

Model is actually convert your python code to the database which you are using

Image description

  • Now, go to views.py file under BookAPI directory Views are used to create and retrieve data from an end point

Image description

  • Now, create a file urls and copy the code from urls file of your project Folder and paste in the urls file of your application

Urls are used to create endpoints and call views to send and receive data

Image description

  • Now, go to urls of your project

Image description

  • Now create migrations using command python manage.py makemigrations
  • Now migrate python manage.py migrate

Now, run
Python manage.py runserver

Top comments (0)