Lesson 59 of 60 – Complete Django Website Project
98%

Complete Django Website Project

In this lesson, we will bring together the major Django concepts learned throughout this tutorial and design a complete website project.

A complete Django website can contain a homepage, about page, contact page, authentication, database models, forms, search, pagination, an admin panel, and other application-specific features.

Note: This project is designed as a learning blueprint. You can customize the pages, database models, design, authentication, and features according to your own project requirements.

1. What is a Complete Django Website?

A complete Django website combines multiple Django components into one working application.

A typical website may contain:

  • Homepage
  • About page
  • Contact page
  • User registration
  • Login and logout
  • Database models
  • Forms
  • Search
  • Admin panel

2. Project Planning

Before writing code, plan the website structure.

For example, an education website could contain:

Home
About
Courses
Students
Blog
Contact
Login
Register
Admin

Planning helps keep the project organized.

3. Create the Django Project

Create the main Django project:

django-admin startproject mywebsite

Move into the project directory:

cd mywebsite

Run the development server:

python manage.py runserver

4. Create Application

Create an application for the website's main functionality.

python manage.py startapp main

Add the app to INSTALLED_APPS.

INSTALLED_APPS = [

    ...
    "main",

]

5. Project Structure

mywebsite/
│
├── manage.py
│
├── mywebsite/
│   ├── settings.py
│   ├── urls.py
│   ├── asgi.py
│   └── wsgi.py
│
└── main/
    ├── migrations/
    ├── templates/
    │   └── main/
    ├── static/
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── models.py
    ├── forms.py
    ├── urls.py
    ├── views.py
    └── tests.py

6. Create Homepage View

Create a homepage view in main/views.py.

from django.shortcuts import render

def home(request):

    return render(
        request,
        "main/home.html"
    )

7. Create About View

def about(request):

    return render(
        request,
        "main/about.html"
    )

The view simply renders the About template.

8. Create Contact View

def contact(request):

    return render(
        request,
        "main/contact.html"
    )

The Contact page can later be connected to a contact form and database model.

9. Create Application URLs

Create main/urls.py.

from django.urls import path
from . import views

urlpatterns = [

    path(
        "",
        views.home,
        name="home"
    ),

    path(
        "about/",
        views.about,
        name="about"
    ),

    path(
        "contact/",
        views.contact,
        name="contact"
    ),

]

10. Include Application URLs

Connect the application URLs to the main project.

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

urlpatterns = [

    path(
        "admin/",
        admin.site.urls
    ),

    path(
        "",
        include("main.urls")
    ),

]

11. Create Templates

Create a templates directory for the main application.

main/
└── templates/
    └── main/
        ├── home.html
        ├── about.html
        └── contact.html

Django will render these HTML files through the views.

12. Create a Base Template

A base template can contain common website elements such as the header, navigation, and footer.

<!DOCTYPE html>

<html>

<head>

    <title>
        {% block title %}
        My Website
        {% endblock %}
    </title>

</head>

<body>

    <nav>

        <a href="{% url 'home' %}">
            Home
        </a>

        <a href="{% url 'about' %}">
            About
        </a>

        <a href="{% url 'contact' %}">
            Contact
        </a>

    </nav>

    {% block content %}
    {% endblock %}

</body>

</html>

13. Template Inheritance

Child templates can extend the base template.

{% extends "main/base.html" %}

{% block title %}
Home
{% endblock %}

{% block content %}

<h1>
Welcome to My Website
</h1>

{% endblock %}

This prevents repeating common HTML across every page.

14. Static Files

Static files include CSS, JavaScript, and images.

A common structure is:

main/
└── static/
    └── main/
        ├── css/
        │   └── style.css
        ├── js/
        │   └── script.js
        └── images/

In templates:

{% load static %}

<link
    rel="stylesheet"
    href="{% static 'main/css/style.css' %}"
>

15. Create a Website Model

Suppose the website needs a Course model.

from django.db import models

class Course(models.Model):

    name = models.CharField(
        max_length=150
    )

    description = models.TextField()

    fee = models.DecimalField(
        max_digits=10,
        decimal_places=2
    )

    duration = models.CharField(
        max_length=100
    )

    def __str__(self):
        return self.name

16. Run Model Migrations

Create and apply migrations after adding the model.

python manage.py makemigrations

python manage.py migrate

The database table for the Course model will be created.

17. Display Database Records

The homepage can retrieve courses from the database.

from .models import Course

def home(request):

    courses = Course.objects.all()

    return render(
        request,
        "main/home.html",
        {
            "courses": courses
        }
    )

18. Display Courses in Template

{% for course in courses %}

    <div>

        <h2>
            {{ course.name }}
        </h2>

        <p>
            {{ course.description }}
        </p>

        <p>
            Fee:
            {{ course.fee }}
        </p>

        <p>
            Duration:
            {{ course.duration }}
        </p>

    </div>

{% empty %}

    <p>
        No courses available.
    </p>

{% endfor %}

19. Create a Contact Model

A contact form can save visitor messages in the database.

class Contact(models.Model):

    name = models.CharField(
        max_length=100
    )

    email = models.EmailField()

    subject = models.CharField(
        max_length=200
    )

    message = models.TextField()

    created_at = models.DateTimeField(
        auto_now_add=True
    )

    def __str__(self):
        return self.name

20. Contact Form

A ModelForm can be used for the Contact model.

from django import forms
from .models import Contact

class ContactForm(forms.ModelForm):

    class Meta:

        model = Contact

        fields = [
            "name",
            "email",
            "subject",
            "message"
        ]

21. Contact View

from django.shortcuts import render, redirect

def contact(request):

    if request.method == "POST":

        form = ContactForm(
            request.POST
        )

        if form.is_valid():

            form.save()

            return redirect(
                "contact"
            )

    else:

        form = ContactForm()

    return render(
        request,
        "main/contact.html",
        {
            "form": form
        }
    )

22. User Authentication

A complete website can include registration, login, logout, and protected pages.

from django.contrib.auth.decorators import login_required

@login_required
def dashboard(request):

    return render(
        request,
        "main/dashboard.html"
    )

Only authenticated users can access the protected view.

23. Add Search Functionality

Search allows visitors to find database records quickly.

query = request.GET.get(
    "q",
    ""
).strip()

courses = Course.objects.all()

if query:

    courses = courses.filter(
        name__icontains=query
    )

The search can be displayed on a course listing page.

24. Add Pagination

Pagination can divide a large list into smaller pages.

from django.core.paginator import Paginator

paginator = Paginator(
    courses,
    10
)

page_number = request.GET.get(
    "page"
)

page_obj = paginator.get_page(
    page_number
)

The template can display the current page of courses.

25. Django Admin Panel

The Django admin panel provides an interface for managing database records.

from django.contrib import admin
from .models import Course, Contact

admin.site.register(
    Course
)

admin.site.register(
    Contact
)

Create an administrator account with:

python manage.py createsuperuser

26. Add Django REST API

A complete Django website can also provide REST API endpoints for mobile applications or JavaScript clients.

pip install djangorestframework

A serializer can convert model data into API-friendly representations.

from rest_framework import serializers

class CourseSerializer(
    serializers.ModelSerializer
):

    class Meta:

        model = Course

        fields = "__all__"

27. Production Preparation

Before deploying a Django website, review the project's production settings and configuration.

  • Set DEBUG = False.
  • Configure ALLOWED_HOSTS.
  • Keep SECRET_KEY secure.
  • Configure static files.
  • Configure media files when required.
  • Use a suitable production database.
  • Configure HTTPS.
  • Protect sensitive configuration values.
  • Run Django deployment checks.
python manage.py check --deploy

28. Complete Website Workflow

User
  ↓
Browser
  ↓
Django URL
  ↓
View
  ↓
Form / Model / ORM
  ↓
Database
  ↓
View
  ↓
Template
  ↓
HTML Response
  ↓
Browser

API Client
  ↓
Django API URL
  ↓
APIView / ViewSet
  ↓
Serializer
  ↓
Database
  ↓
JSON Response
  ↓
API Client

29. Complete Django Website Structure

mywebsite/
│
├── manage.py
│
├── mywebsite/
│   ├── settings.py
│   ├── urls.py
│   ├── asgi.py
│   └── wsgi.py
│
└── main/
    ├── migrations/
    ├── templates/
    │   └── main/
    │       ├── base.html
    │       ├── home.html
    │       ├── about.html
    │       ├── contact.html
    │       ├── login.html
    │       └── dashboard.html
    │
    ├── static/
    │   └── main/
    │       ├── css/
    │       ├── js/
    │       └── images/
    │
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── forms.py
    ├── models.py
    ├── urls.py
    ├── views.py
    └── tests.py

30. Complete Django Website Project Summary

A complete Django website combines the major concepts learned throughout the tutorial into one practical application.

  • Use Django Projects and Apps to organize the application.
  • Use URLs to route browser requests.
  • Use Views to implement application logic.
  • Use Templates to generate HTML pages.
  • Use Template Inheritance for reusable layouts.
  • Use Models and ORM for database operations.
  • Use ModelForms for database forms.
  • Use Authentication for user accounts.
  • Use Search and Pagination for large datasets.
  • Use Django Admin for data management.
  • Use Static Files for CSS, JavaScript, and images.
  • Use Django REST Framework when an API is required.
  • Prepare security and configuration before deployment.

📌 Key Points

  • A complete Django website combines multiple Django components.
  • Models and ORM handle database operations.
  • Views process requests and return responses.
  • Templates create the website interface.
  • Forms handle user input.
  • Authentication protects user-specific features.
  • Search and pagination improve usability.
  • Django Admin helps manage database records.
  • Static files provide CSS, JavaScript, and images.
  • REST Framework can provide APIs for external clients.
  • Production configuration and security should be reviewed before deployment.

🧠 Quick Quiz

Question: Which Django component is primarily responsible for processing a request and returning a response?