o‘zing o‘rgan
Django: Building Websites Lesson 1 / 15
Pito

What Django is and your first project

Frameworks, MVT, projects and apps, runserver

Chapter 1. Django basics 20 minutes 4 questions

Django is a Python web framework: a ready-made "skeleton" and toolkit for building sites. Users, the database, forms, the admin panel, security — all ready, and you write the part that's unique to your site. It's named after the jazz guitarist Django Reinhardt; its first open release came out in 2005.

Instagram's backend is built on Django. This very site you're reading is written in Django too.

MVT: three parts

Part Job In the file
Model the data structure and database models.py
View takes the request and prepares the response views.py
Template how the HTML page looks templates/*.html

Plus the URL map that connects them (urls.py): which view answers which address.

browser ──/courses/──▶ urls.py ──▶ view ──▶ model (database) ──▶ view ──▶ template ──▶ HTML ──▶ browser

Installing and your first project

python -m venv .venv
.venv\Scripts\activate                  # Linux/macOS: source .venv/bin/activate
pip install django
django-admin startproject site_project .
python manage.py runserver

Open http://127.0.0.1:8000/ — Django's welcome page appears. 🎉

Projects and apps

The project is the whole site. An app is an independent part of it (a blog, a shop, users):

python manage.py startapp blog
site_project/         ← project settings
├── settings.py       ← add 'blog' to INSTALLED_APPS
├── urls.py
blog/                 ← the app
├── models.py
├── views.py
├── admin.py
manage.py             ← management commands

On this site, for example, accounts (users), courses (courses) and quizzes (quizzes) are separate apps.

💡 manage.py is the main tool for working with Django: runserver, makemigrations, migrate, createsuperuser, test.

Check yourself

Question 1 / 4

What do the letters MVT stand for in Django?

Choices

Question 2 / 4

Which file connects addresses to views?

Choices

Question 3 / 4

Which command starts the development server?

Choices

Question 4 / 4

Project versus app?

Choices