Getting Started with Django: A Beginner’s Guide to Building Web Applications

By | July 28, 2026

Django is a high-level Python web framework that enables rapid development of secure, maintainable, and scalable web applications. With its robust architecture, extensive libraries, and large community support, Django has become a popular choice among web developers. In this article, we will provide a step-by-step guide for beginners to get started with Django and build their first web application.

Prerequisites

Before diving into Django, you should have:

  • Basic knowledge of Python programming language
  • Familiarity with HTML, CSS, and JavaScript
  • A code editor or IDE (Integrated Development Environment) of your choice
  • A virtual environment (optional but recommended)

Installing Django

To install Django, follow these steps:

  1. Open your terminal or command prompt.
  2. Install pip, the Python package manager, if you haven’t already: sudo apt-get install python3-pip (for Ubuntu-based systems) or pip3 install --upgrade pip (for other systems).
  3. Install Django using pip: pip3 install django
  4. Verify the installation by running django-admin --version

Creating a New Django Project

To create a new Django project, follow these steps:

  1. Open your terminal or command prompt.
  2. Navigate to the directory where you want to create your project.
  3. Run the command django-admin startproject projectname (replace “projectname” with your desired project name).
  4. This will create a new directory with the basic structure for a Django project.

Understanding the Django Project Structure

A Django project consists of several directories and files:

  • manage.py: a command-line utility for interacting with your project
  • projectname/: the project directory, containing settings, URLs, and wsgi files
  • projectname/settings.py: project-wide settings, such as database connections and installed apps
  • projectname/urls.py: project-wide URL configuration
  • projectname/wsgi.py: WSGI (Web Server Gateway Interface) configuration

Creating a New Django App

In Django, a project can have multiple apps. To create a new app, follow these steps:

  1. Navigate to the project directory.
  2. Run the command python manage.py startapp appname (replace “appname” with your desired app name).
  3. This will create a new directory with the basic structure for a Django app.

Understanding the Django App Structure

A Django app consists of several directories and files:

  • admin.py: admin interface configuration
  • apps.py: app configuration
  • models.py: data models
  • tests.py: unit tests
  • views.py: views (functions that handle HTTP requests and return HTTP responses)

Defining Models

In Django, models represent data structures. To define a model, create a new class in models.py that inherits from django.db.models.Model. For example:
python
from django.db import models

class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=100)
publication_date = models.DateField()

Creating and Applying Migrations

After defining models, you need to create and apply migrations to update the database schema. Run the following commands:
bash
python manage.py makemigrations
python manage.py migrate

Creating Views

Views are functions that handle HTTP requests and return HTTP responses. To create a view, define a new function in views.py that takes a request object as an argument. For example:
python
from django.http import HttpResponse
from.models import Book

def book_list(request):
books = Book.objects.all()
output = ‘, ‘.join([book.title for book in books])
return HttpResponse(output)

Mapping URLs

To map URLs to views, create a new URL pattern in urls.py. For example:
python
from django.urls import path
from. import views

urlpatterns = [
path(‘books/’, views.book_list, name=’book_list’),
]

Running the Development Server

To run the development server, execute the following command:
bash
python manage.py runserver

This will start the server, and you can access your web application at http://localhost:8000/.

Conclusion

In this article, we provided a step-by-step guide for beginners to get started with Django and build their first web application. We covered installing Django, creating a new project and app, defining models, creating and applying migrations, creating views, mapping URLs, and running the development server. With this foundation, you can now start building your own web applications using Django. Remember to explore the official Django documentation and community resources for further learning and support. Happy coding!