top of page
Search

Getting Started with Django: A Beginner’s Guide for High School Students

Are you a high school student interested in web development but don’t know where to start? Do you love Python and want to use it to build websites? If so, Django is the perfect framework for you!


Django is a powerful Python-based web framework that helps developers create websites quickly and efficiently. In this blog, we’ll break down what Django is, how to get started as a beginner, and walk you through creating your first simple Django project!



Let’s dive in! 🚀


 

What is Django?


Django is a high-level Python web framework designed for building secure, scalable, and maintainable websites. It was built with the philosophy of:


Fast development – Build web apps quickly without reinventing the wheel.

Secure by default – Django comes with built-in security features.

Scalability – Used by big companies like Instagram, Pinterest, and Spotify.


With Django, you can build blogs, e-commerce sites, social media apps, dashboards, and more! But don’t worry—today, we’re keeping it simple and building a basic To-Do app so you can learn by doing.


 

Step 1: Installing Django


Before we start coding, we need to install Django on our computer. Follow these steps:


1. Install Python (if you don’t have it yet)

Download and install Python from python.org.


2. Create a Virtual Environment

A virtual environment keeps your Django project organized. Open your terminal or command prompt and run:

python -m venv myenv

Activate the virtual environment:

  • Windows: myenv\Scripts\activate

  • Mac/Linux: source myenv/bin/activate


3. Install Django

Now, install Django with:

pip install django

Boom! 🎉 You now have Django installed.


 

Step 2: Creating Your First Django Project


Now, let’s create our first Django project called To-Do App.


Run this command in your terminal:

django-admin startproject todo_project
cd todo_project

This creates a project folder with files like settings.py, urls.py, and manage.py. These files help manage your web app.


Next, start the server to see Django in action:

python manage.py runserver

Open your browser and go to http://127.0.0.1:8000/. If you see the Django welcome page, congrats! 🎉 You’ve successfully set up Django!


 

Step 3: Creating a To-Do App in Django


Now, let’s create a simple To-Do List app where users can add and view tasks.


1. Create a Django App

Inside your project folder, run:

python manage.py startapp todo

This creates a folder called todo, where we’ll write the logic for our to-do list.


2. Add the App to Django’s Settings


Open todo_project/settings.py and add "todo" under INSTALLED_APPS:

INSTALLED_APPS = [
   'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'todo',  # Add this

]

3. Create the To-Do Model

Now, let’s define a Task model (which represents a to-do list item). Open todo/models.py and add:

from django.db import models
class Task(models.Model):

    title = models.CharField(max_length=200)

    completed = models.BooleanField(default=False)

    def __str__(self):

        return self.title

This tells Django that each task has a title (text) and a completed status (True or False).


4. Apply Migrations

Whenever we change models, we need to run migrations:

python manage.py makemigrations
python manage.py migrate

This creates the necessary database tables for our tasks.


 

Step 4: Building a Simple To-Do List View


1. Create a View to Show Tasks


Open todo/views.py and add:

from django.shortcuts import render
from .models import Task

def task_list(request):
	tasks = Task.objects.all()
	return render(request, 'todo/task_list.html', {'tasks': tasks})

This fetches all tasks from the database and passes them to our HTML template.


2. Set Up the URL


Open todo/urls.py (create it if it doesn’t exist) and add:

from django.urls import path

from .views import task_list
urlpatterns = [
	path('', task_list, name='task_list'),
]

Now, include this in the main project’s urls.py:

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

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

3. Create the HTML Template


Inside the todo folder, create a templates folder, then a todo folder inside it. Create a file named task_list.html:


<!DOCTYPE html>
<html>

<head>
	<title>To-Do List</title>
</head>
<body>
	<h1>My To-Do List</h1>
	<ul>
		{% for task in tasks %}
			<li>{{ task.title }} - {% if task.completed %} ✅ {% else %} ❌ {% endif %}</li>
		{% endfor %}

	</ul>
</body>
</html>

Now, restart the server:

python manage.py runserver

Go to http://127.0.0.1:8000/, and you should see your tasks displayed! 🎉


Step 5: Adding Tasks via Django Admin


Want to add new tasks without coding? Use Django’s built-in admin panel!


  1. Create a superuser:

python manage.py createsuperuser

Enter your username, email, and password.


  1. Open todo/admin.py and register the Task model:

from django.contrib import admin
from .models import Task

admin.site.register(Task)

  1. Now, restart the server and go to http://127.0.0.1:8000/admin/.

  2. Log in with your superuser credentials and add tasks through the admin panel!




 

Final Thoughts: You Just Built a Django Web App! 🚀


👏 Congratulations! You just built a To-Do list web app using Django! 🎉

This is just the beginning—Django allows you to build powerful, scalable web applications with user authentication, databases, and more.


Where to Go Next?


✔️ Add a form to let users create new tasks.

✔️ Style the page using CSS.

✔️ Explore Django’s authentication system for user logins.

💡 Want more beginner-friendly coding tutorials? Subscribe to our newsletter and start your web development journey today! 🚀✨

 
 
 

Comments


Inspiring students to unlock their potential and create meaningful academic journeys with expert guidance and mentorship.

1603 Capitol Ave Suite 310
Cheyenne, WY 82001

Stay connected, subscribe to our newsletter

Thank you for subscribing!

bottom of page