Django

Django tutorial written like I’m sitting next to you explaining it step by step (as of early 2026). We’ll build a classic polling application (very similar to the official one but explained more conversationally, with extra tips, common mistakes, and modern touches).

Current stable version: Django 6.0.1 (released January 2026). It supports Python 3.12–3.14.

Let’s go!

0. Before we start – Prerequisites (5–10 minutes)

Make sure you have:

  • Python 3.12 / 3.13 / 3.14 installed Check: python –version or python3 –version
  • pip is up to date python -m pip install –upgrade pip
  • A code editor (VS Code + Python extension is great)
  • Basic terminal comfort (cd, mkdir, etc.)

If something is missing → Google “install Python 3.13 Windows/macOS/Linux” for your OS.

1. Create virtual environment (very important!)

Never install packages globally.

Bash

You should now see (venv) in your prompt.

2. Install Django 6.0.1

Bash

Check it worked:

Bash

3. Create the Django project

Bash

Note the dot (.) at the end → it creates the project in the current folder (cleaner structure).

Now your folder looks like:

text

4. Run the development server (first “Hello World”)

Bash

Open http://127.0.0.1:8000/

You should see the beautiful “The install worked successfully!” rocket page.

→ Press Ctrl+C to stop it when done.

5. Create your first app – polls

Django projects are made of apps. One project → many reusable apps.

Bash

New folder appears: polls/

Typical app structure:

text

6. Tell Django about your new app

Open mysite/settings.py → find INSTALLED_APPS list and add:

Python

(Using PollsConfig is the modern / recommended way since Django 1.9+)

7. Write your first view (very simple)

Open polls/views.py

Python

This is the most basic view possible.

8. Connect view → URL

Create polls/urls.py (new file!)

Python

Now tell the main project to include this URLconf.

Open mysite/urls.py and change it to:

Python

9. Test it!

Bash

Go to: http://127.0.0.1:8000/polls/

→ You should see: Hello, world. You’re at the polls index.

🎉 First working page!

10. Models – Database time (Question + Choice)

Open polls/models.py

Python

Important notes:

  • ForeignKey = many-to-one relationship
  • on_delete=models.CASCADE = if question deleted → delete all choices
  • __str__ = better display in admin & shell

11. Make & run migrations

Bash

You’ll see something like:

text

Django auto-creates id primary key for every model.

12. Play with the API in shell (very useful for learning)

Bash
Python

Exit with exit()

13. Activate the killer feature – Django Admin

Create superuser:

Bash

Follow prompts (username, email, password).

Start server again → http://127.0.0.1:8000/admin/

Login → but you see nothing about polls yet.

Fix: open polls/admin.py

Python

Refresh admin → now you can create/edit Questions and Choices!

Pro tip 2026: make it nicer

Python

Much better UX!

14. Next steps – Template + Detail view (brief roadmap)

Create polls/templates/polls/index.html

HTML

Update view:

Python

And continue to:

  • Detail view
  • Results view
  • Voting (POST handling + F() expressions)
  • Generic class-based views
  • Forms
  • Static files & templates inheritance
  • Testing
  • Deployment (Railway.app, Render, Fly.io are popular in 2026)