Introduction

Welcome to the first lesson of our course on building a TODO app using Django and Django REST Framework (DRF). In this lesson, we'll lay the foundation by setting up our development environment. A solid setup is crucial for effective and efficient development. By the end of this lesson, you will have installed the necessary libraries, created a Django project and app, and configured the basic settings and routing needed to get started.

This initial setup acts as the backbone of any Django-based project. Understanding how to configure and initialize your environment correctly is essential for the smooth development of our TODO app, which we'll build upon in future lessons.

Installing Django and DRF

Before we start creating our project, we need to install Django and DRF. These libraries form the core of our development environment.

To install Django and DRF, open your terminal and run the following command:

pip install django djangorestframework

This command installs Django, a high-level Python web framework that encourages rapid development, and Django REST Framework, a powerful and flexible toolkit for building Web APIs.

Execute it in a Python virtual environment to keep your project dependencies isolated. These libraries will come pre-installed in CodeSignal's environment.

Creating a Django Project

Next, we'll create a new Django project. A Django project is a collection of settings for an instance of Django, including database configuration, application-specific settings, and application initialization.

Run the following commands in your terminal:

django-admin startproject myproject
cd myproject

Here's what each command does:

  • django-admin startproject myproject: This command creates a new directory called myproject, which contains the initial project structure.
  • cd myproject: This changes your current directory to myproject.

At this point, your project structure should look like this:

myproject/
    manage.py
    myproject/
        __init__.py
        settings.py
        urls.py
        wsgi.py
Creating a Django App

Now that we have our project, we need to create a Django app. An app is a web application that does something, like a blog system, a database of public records, or, in our case, a TODO app. A project can have multiple apps. For example, you could have apps for authentication system and main website functionality to nicely separate their logic.

Run the following command inside the myproject directory:

django-admin startapp myapp

This command creates a new directory called myapp with the following structure:

myapp/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal