Skip to main content

Command Palette

Search for a command to run...

A Beginner’s Guide to Setting Up a Django Rest Framework(DRF) Project

Updated
3 min read
A Beginner’s Guide to Setting Up a Django Rest Framework(DRF) Project

Welcome to a beginner’s guide to setting up a Django REST Framework project!

To keep things simple and short, Django REST Framework (DRF) is a powerful tool built on top of Django that makes it easy to build RESTful APIs. In this article, I’ll walk you through the easy steps to set up a DRF project.

To work with DRF, you just need a basic understanding of Python, Django, and to have Python (version 3.4 or higher) installed on your PC.

Let’s get to it! 🚀

Once you’ve got the prerequisites covered, open your terminal — whether it’s CMD, Bash, or the one in VS Code, whichever you prefer. The first thing you want to do is create a new folder where your project will live by running mkdir my-project. You can name it whatever you like, but let’s call it my-project.

After creating the folder, move into it so you’re working inside the right directory, you do that by running cd my-project.

Inside this folder, the next step is to create a virtual environment using Python, which helps keep your project dependencies isolated so that whatever you install here doesn’t interfere with other projects on your system. You can create it by running python -m venv venv.

Once that’s done, activate the virtual environment. The command differs slightly depending on your operating system: on Windows, it’s source venv/Scripts/activate, while on Mac OS or Linux, it’s source venv/bin/activate.

When activated, you’ll notice the environment name (venv) appear at the beginning of your terminal line, that’s how you know your virtual environment is now active.

You should have something like this in you terminal:

With that set up, it’s time to install Django and Django REST Framework. Django serves as the core framework, while DRF builds on top of it to make creating APIs easier and more structured. You can install both at once using the Python package manager (pip). You do this by running pip install django djangorestframework.

The next thing to do is to create your Django API project. You can do that by running python -m django startproject myproject .. After creating your project, the next step is to create your Django app, this is where you’ll write your API views and models. You can do that by running python -m django startapp myapi.

You should have something like this in your terminal:

After creating both your project and app, you can open your entire setup in your code editor by simply running the code . command if you’re using VS Code. You’ll now see your project structure neatly laid out. It should look like this:

And that’s it! you’ve successfully set up your first Django REST Framework project! 🎉 From here, you can start building out your models, views, and serializers to bring your API to life. Watch out for my next articles, where I’ll walk you through building actual endpoints using Django REST Framework. Thanks for sticking with me till the end. Cheers! 🚀