Audience

  • People who already know Django but don't know Django Rest framework.
  • Though, you can still proceed if you know zero Django.

Introduction

I'm planning on writing a series on Django Rest Framework. The series aims to provide a very concise introduction to the framework. We would kickstart the series by discussing dependency management using poetry (check out uv for a great alternative).

Creating a project

Assume that we now have poetry installed. I also hope that we are Linux.

(1) Create a directory named dog-house.
(2) Run

cd dog-house
poetry init

to initialize the project directory.

The prompt would pop up. We provide important fields as below:

Package name [dog-house]:             # Press Enter
Compatible Python versions [>=3.12]:  # Press Enter
Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no

Note that some non-important fields are left out.

(3) We that create a file named poetry.toml with the following content:

[virtualenvs]
in-project = true

This will flag the creation of the directory .venv locally.

(4) We can add dependencies by running poetry add . The following packages will be installed:

To keep it simple, we will not use PostgreSQL (and psycopg). Instead, we'll only use SQLite (default).

poetry add Django
poetry add djangorestframework
poetry add django-rest-knox

(4) To create a Django project, we run

poetry run django-admin startproject dog_house

(5) We can check if everything is working properly by running

cd dog_house
poetry run python manage.py runserver

Follow the URL generated in the terminal to see the greeting page.

Outro

That's it for today. See you next time!!

References

https://docs.djangoproject.com/en/5.2/intro/tutorial01/