How to initialize a backend app using Django REST Framework - bounswe/bounswe2024group11 GitHub Wiki

Overview

This document serves as a comprehensive guide to setting up a backend application using Django and Django REST Framework. It covers the installation process, project setup, and initial API creation.

Introduction

The purpose of this backend application is to provide an API service using Django, a high-level Python web framework, and Django REST Framework, a powerful toolkit for building Web APIs.

Prerequisites

Required Installations

  • Python
  • pip

Setting Up Your Development Environment

Installing Python and pip

Follow the steps appropriate for your operating system to install Python and pip from here.

Assuming the repo will have backend, web, and mobile parts together, create a directory for the backend app inside your project's root directory.

mkdir ./backend

Optionally, you may create directories for web and mobile parts here.

mkdir web mobile

Before continuing, change your directory to backend.

cd ./backend

Creating a Virtual Environment

Create and activate a virtual environment to manage dependencies separately from the system Python.

Note: While initializing our project, we decided to use Python 3.12. So create your virtual environments accordingly. You may want to take a look at Python Documentation.

create a virtual environment

On bash/zsh shells (i.e., on macOS and the most of the Linux-based distros)

python3 -m venv <venv_name>

On Windows

python -m venv <venv_name>

Activate the virtual environment

On bash/zsh shells (i.e., on macOS and the most of the Linux-based distros)

source ./<venv_name>/bin/activate

On Windows (either of them)

<venv_name>\Scripts\Activate.ps1 (Powershell)
<venv_name>\Scripts\activate.bat (cmd)

Remaining codes

django-admin startproject <myproject>
python manage.py startapp <myapp>
# update settings.py, Installed_apps, etc.
# Building first API
⚠️ **GitHub.com Fallback** ⚠️