Getting Started with Django

A Beginner’s Guide to Setting Up a Django Project and Building a CRUD Application

Getting Started with Django

The "People Records" project is a beginner-friendly web application built with Django, utilizing basic HTML, CSS, and Bootstrap. It enables users to perform essential CRUD (Create, Read, Update, Delete) operations. Additionally, the application features a custom login system integrated with Django’s admin functionality for user authentication management. This project is designed to showcase fundamental coding principles and core functionalities.


Setting Up a Django Project

Before starting a Django project, the first step is to create a virtual environment.

Creating a Virtual Environment

Navigate to the directory where you want to set up your project, then run the following command:

python -m venv "Your Environment Name"
  1. Once the virtual environment is created, navigate to its directory using the cd command. Then, go to the scripts folder and execute the activate script to activate the virtual environment. In summary, follow these steps:
directory > cd "Your Environment Name"/Scripts/
directory > .\\activate

Creating A Django Project

To start a Django project, use the following command:

django-admin startproject "Project Name"

In Django, a single project can consist of multiple apps.

After creating the project, a project directory will be generated, containing several important files. Inside this directory, there will be another folder with the same project name, which holds essential configuration files that will be discussed later. Additionally, the project directory includes manage.py, a crucial script used for running the server, applying migrations, and performing various other functions.

Files Included in the Project :

This basic project currently contains no additional functionality, so running it will only display the default boilerplate template.

To start the project, execute the following command in the terminal:

python manage.py runserver

Django Boiler Plate


Creating an App

To create a new app in Django, use the following command:

django-admin startapp "App Name"

This will generate an app directory inside the project folder, alongside the main project directory. The newly created app folder will contain the following essential files:

Files Inside the App Directory :

__init__.py → May include the main function (to be defined later). admin.py → Used to register models created in models.py for database management. apps.py → Handles app-specific configurations. models.py → Defines database models that will be stored in the database. tests.py → Used for writing test cases to verify functionality. views.py → Contains functions that handle requests and render responses for the frontend.

Adding the App to Django Settings :

To integrate the newly created app into the project, add it to the INSTALLED_APPS list in the settings.py file located inside the main project folder.

Defining URL Paths :

Next, the app’s URLs need to be linked to the main project's URL configuration. This is done by modifying the urls.py file in the main project directory as shown below:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [    
    path('admin/', admin.site.urls),    
    path("", include("practice_app.urls")),
]

In the above code :

  • The path and include functions are imported from django.urls.

  • The admin module is imported by default.

  • The urlpatterns list maps URL paths, where "practice_app.urls" refers to the urls.py file inside the practice_app directory, which contains all the necessary routes for the app.


Stay tuned for the next section,

where we'll dive into implementing CRUD operations in Django! 🚀