Python Tutorial
Django Get Started
Check that Python and pip work, then prepare a folder for the Django project you will build in the next chapters.
Check Python
Django 5 needs Python 3.10 or newer. In a terminal:
python --version
# Python 3.12.4On some Windows installs the command is py instead of python:
py --versionCheck pip
pip installs Python packages. Confirm it is available:
python -m pip --versionUpgrade pip if it is old:
python -m pip install --upgrade pipCreate a Project Folder
Keep Django work in its own directory so settings and the database stay together.
mkdir django-tutorial
cd django-tutorialAll later commands in this section assume you are inside django-tutorial.
What Comes Next
Do not install Django globally. The next chapter creates a virtual environment so this project's packages stay isolated from other Python work on your machine.
📘 Real-World Deep Dive
Knowing <strong>Django Get Started (Django)</strong> well is what turns Django from a curiosity into a daily tool — you'll reach for it in nearly every real project.
Real-Life Scenario
An end-to-end usage of Django Get Started that you'd actually see in a data pipeline or analytics notebook.
Real-Life Example
# minimal Django "hello" view (project: mysite, app: pages)
from django.http import HttpResponse
from django.urls import path
def hello(request):
return HttpResponse("Hello from Django!")
urlpatterns = [path("", hello)]
# run with:
# python manage.py runserverExpected Output
(no output)Common mistakes
- Forgetting to call
.save()on a model instance after mutation silently persists nothing. - Reading every row with
Model.objects.all()on a 1 M-row table OOMs the worker — use.iterator()for streaming. - Queries inside loops produce N+1 problems — pull related rows with
select_related/prefetch_related. - Treating Django Get Started as a black box without reading the docs — the API has subtle defaults that bite when you scale.
🚀 Performance & Best Practices
- Add database indexes (
db_index=TrueorMeta.indexes) on columns used infilter. - Use
cache_pageon read-heavy views and setCONN_MAX_AGEto keep DB connections warm. - Generate migrations with
python manage.py makemigrations --dry-run --verbosity 3and review before committing. - When working with Django, prefer vectorised / batched operations over Python loops.
🧪 Try It Yourself
- Reproduce the snippet on a representative slice of your own data.
- Profile the snippet with
cProfileortimeitand find the single biggest improvement. - Generalise the snippet into a small, reusable function you can drop into future projects.