Django for Beginners
■ Episode 1: How Django Works (MTV Model)
(Last Updated: 2024.11.12)
Image of the Django framework
You can read this article in 5 minutes!
(If the image looks small, try rotating your phone)
"There’s so little Japanese documentation!"
That was my first impression when using Django. Compared to other full-stack frameworks like Ruby on Rails or Laravel, Japanese books and video materials are relatively scarce. This can be seen as a drawback when using Django. However, in recent years, more beginner-friendly resources have been published, and the situation is gradually improving. If you learn from highly-rated books or courses on platforms like Udemy, you could become proficient with Django in as little as three months—or six months at the latest. Django is a fantastic full-stack framework that covers all the bases. If you’re interested, now’s a great time to give it a try.
Globally, Django is one of the most widely used full-stack frameworks. Platforms like Instagram and YouTube are built with Django. One major reason companies adopt Django is its robust set of built-in features, such as user management and security functions. (Although frameworks like Rails and Laravel also have rich features, Django’s strengths are still significant.) Additionally, Django is written in Python, which makes it highly compatible with machine learning applications. You can do preprocessing, analysis, and API development all in the same language. This is a clear advantage over other frameworks.
Django has been the leading Python framework since 2005 and will likely continue to be widely used in the future. Its core features are stable and mature, reducing the risk of frequent, disruptive changes. The upgrade roadmap is also available on the official site, offering peace of mind for long-term maintenance. Recent updates, like support for Python 11 and asynchronous processing in Django 4, are also exciting. Django’s development shows no signs of slowing down.
This article will explain what Django is in a simple way, even for beginners. To avoid overwhelming you, Episode 1 focuses on how Django works and how to get started.
[Table of Contents]
How Django Works (MTV Model)
Getting Started with Django: Installation
1. How Django Works (MTV Model)
Django’s structure can be analyzed through the lens of MVC as shown in the diagram below.
Django Structure in MVC Terms
Django’s structure is often referred to as MTV, rather than MVC. It takes the "T" from Template and the "V" from Views.py. However, Django’s View is not the "view" in MVC; it corresponds more closely to the Controller in MVC. Meanwhile, the Template is what you actually see—similar to MVC’s View. So first, it's important to understand this naming difference.
Specifically:
① `urls.py` handles routing
② `models.py` interacts with the database (DB)
③ `views.py` fetches data from the DB, processes it, and passes it to the Template
④ The Template renders the final HTML output
In short, `views.py` acts as the bridge between the Model (DB) and the Template (UI).
Here's an example to illustrate this. You can see how `views.py` specifies both the Model and the Template. Once you understand the overall structure and the role of each file, the rest is just hands-on practice. The concept isn’t much different from other frameworks.
Code Example: Django Structure
2. Getting Started with Django: Installation
This section describes how to get started *without* using a virtual environment. Assume Python 3 is already installed. On Windows, open Command Prompt; on Mac, open Terminal. Then run:
pip install django
After successful installation, create a project with:
django-admin startproject projectname
If that doesn’t work, try:
python -m django startproject projectname
This will create your project directory. Open it with VSCode, and in the Terminal, run:
python manage.py runserver
Django should now be running.
(If Python 2 is also installed, you may need to use `pip3` and `python3` instead.)
You can now start using Django from your local machine anytime.
In the next episode, we’ll explore how to use Django in more detail.
Django running successfully
▼ Recommended Books & Resources
"Django no Tsubo to Kotsu ga Zettai ni Wakaru Hon" by Ryota Ohashi, Shuwa System (Japanese)
"Genba de Tsukaeru Django Kanri Site no Tsukurikata" by Akihito Yokose (Japanese)