🏆 FINAL PROJECT - Build Your First Web Server!

🌐Project: Django Todo Web Server

Build a fully functional web server with Django that manages todo items. Create, read, update, delete (CRUD) operations.

Final Result: http://localhost:8000 → Your live web app!

✅ Prerequisites

  • Python 3.8+ installed
  • Terminal/Command Prompt
  • Complete all previous lessons

Step 1: Setup Virtual Environment

$ python -m venv django_env
$ # Windows:
$ django_env\Scripts\activate
$ # Mac/Linux:
$ source django_env/bin/activate

Step 2: Install Django

(django_env) $ pip install django
(django_env) $ pip install djangorestframework # For API (optional)
pip install django
pip install djangorestframework

Step 3: Create Django Project

(django_env) $ django-admin startproject todo_project .
(django_env) $ python manage.py startapp todos
✅ Project 'todo_project' started ✅ App 'todos' created

Step 4: Define Todo Model

Edit todos/models.py:

from django.db import models

class Todo(models.Model):
    title = models.CharField(max_length=200)
    completed = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    
    def __str__(self):
        return self.title

Step 5: Run Migrations & Test Server

(django_env) $ python manage.py makemigrations
(django_env) $ python manage.py migrate
(django_env) $ python manage.py runserver
✅ Migrations complete ✅ Server running at http://127.0.0.1:8000/

Step 6: Create Views & URLs

1. todos/views.py:

from django.shortcuts import render
from django.http import JsonResponse
from .models import Todo

def todo_list(request):
    todos = Todo.objects.all()
    return JsonResponse({'todos': list(todos.values())})

2. todo_project/urls.py:

from django.urls import path from todos import views urlpatterns = [ path('api/todos/', views.todo_list, name='todo_list'), ]

🎉 Test Your Server!

  1. Run: python manage.py runserver
  2. Open: http://localhost:8000/api/todos/
  3. See: {"todos": []} → SUCCESS! 🎊
Your Django Server is LIVE! 🏆

🧠 Django Project Quiz (6 Questions)

Q1: Create Django project command?

Q2: Database changes command?

Q3: Django model inherits from?

Q4: Run development server?

Q5: Default Django port?

Q6: Virtual environment activate (Linux/Mac)?