Django Framework Tutorial: Learn with Practical Examples

Django is a Python web framework for building websites with views, URL routes, templates, forms and database models. This guide links the lessons in a practical learning order, starting with a local project and progressing to MySQL-backed pages.

Quick start: create and run a local Django project

python -m pip install "Django>=5.2,<5.3"
django-admin startproject plus2net_demo
cd plus2net_demo
python manage.py runserver

Open http://127.0.0.1:8000/ after the server starts. Django includes a development server and uses SQLite by default, so MySQL is not required for the first lessons.

On this page — Show page sectionsHide page sections

What you will build

  • A working project with an application, URL routes and view functions.
  • HTML templates that receive safe output from Python views.
  • GET/POST forms with validation and protection against cross-site request forgery (CSRF).
  • A student database using Django models and migrations.
  • A list/detail interface and Django’s administrative interface.

Start here: installation, views and URLs

Begin with Django installation and your first project. That lesson explains virtual environments, manage.py, app creation, views, URLs, templates and the local server.

my_app/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello from Django")

my_app/urls.py

from django.urls import path
from . import views

urlpatterns = [path("", views.index, name="home")]

Forms and user input

After building a view, learn how to collect and validate data. Basic Django forms explains HTML forms, GET versus POST and CSRF tokens; Django form classes covers field-level validation, dropdowns, checkboxes and radio controls.

Read a query parameter in a view

from django.shortcuts import render

def welcome(request):
    name = request.GET.get("name", "Guest")
    return render(request, "welcome.html", {"name": name})

Query strings, templates and static assets

  • Query strings — collect optional ?id= and ?name= values and validate them before database use.
  • Template for loops — display a list of Python objects with {% for %} and {% empty %}.
  • Static files — include CSS, JavaScript, jQuery and Bootstrap with Django’s static-file system.

Models and databases

Build a common Student model in Django and MySQL. The same fields are used in each database lesson, so you can progress without repeatedly changing schema names. You may work with SQLite locally first.

students/models.py — common model across the database tutorials

from django.db import models

class Student(models.Model):
    name = models.CharField(max_length=100)
    cl = models.CharField(max_length=20, db_column="class")
    mark = models.PositiveSmallIntegerField()
    gender = models.CharField(max_length=20)

    def __str__(self):
        return self.name

Database operations in learning order

A useful Django project structure

Representative project files; Django generates additional support files

plus2net_demo/
├── manage.py
├── plus2net_demo/
│   ├── settings.py
│   └── urls.py
└── students/
    ├── admin.py
    ├── apps.py
    ├── forms.py
    ├── models.py
    ├── urls.py
    ├── views.py
    └── templates/students/
        ├── student_list.html
        ├── student_detail.html
        └── student_form.html

Version and security notes

These lessons use Django 5.2 LTS with supported Python versions, and focus on a coherent local example project with named URLs, templates and models. Review the official Django 5.2 documentation when applying examples to an existing project.

The built-in runserver command is for development, not production hosting. Never publish DEBUG=True, a real database password, or unprotected demonstration actions on a public server.

Suggested learning sequence

StepTutorialWhat you learn
1Install Django and create a projectSet up and run the framework
2GET and POST formsBuild the next component of the same sample project
3Form classes and validationBuild the next component of the same sample project
4Query string parametersBuild the next component of the same sample project
5Template for loopsBuild the next component of the same sample project
6CSS, JavaScript, jQuery and static filesBuild the next component of the same sample project
7MySQL connection and modelsBuild the next component of the same sample project
8Insert form dataBuild the next component of the same sample project
9Insert multiple recordsBuild the next component of the same sample project
10Display and filter MySQL rowsBuild the next component of the same sample project
11List and detail pagesBuild the next component of the same sample project
12Admin interfaceBuild the next component of the same sample project

Frequently asked questions

Do I need MySQL to learn Django?

No. Django uses SQLite by default. Use SQLite for installation, templates and forms; switch to MySQL when you reach the database connection tutorial.

Should I begin with the admin interface?

Start with installation, URLs, views and models first. The admin becomes more useful after a model exists.

Is this a Google Colab course?

No. Django is best learned as a local multi-file web project with its own development server. The tutorials provide copyable file-by-file examples rather than notebooks.

Next: Install Django and create a project

Additional references

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com



28-12-2020

how to display only one record....can you tell me




Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer