Master Django: A Complete Beginner-to-Advanced Tutorial

This guide introduces Django’s fundamentals, explains its MTV architecture, walks through project and app setup, URL routing, views, models, admin customization, database configuration, and essential commands, providing a practical roadmap for quickly building web applications.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Django: A Complete Beginner-to-Advanced Tutorial

Abstract

This concise, practical Django tutorial is designed for beginners of any programming background who want to quickly learn Django and start developing web applications. It also serves as a reference for specific technical points.

Prerequisites

Assume the reader has basic Python knowledge and is familiar with web development concepts such as CSS, JavaScript, and databases.

What is Django?

Django is an open‑source web application framework written in Python. It follows the MVC (Model‑View‑Controller) design pattern, although Django refers to it as MTV (Model‑Template‑View). Created to manage news‑focused websites for the Lawrence publishing group, it was released in July 2005 under the BSD license and is named after the Belgian jazz guitarist Django Reinhardt. Django aims to simplify the development of complex, database‑driven sites, emphasizing component reusability, plug‑ability, agile development, and the DRY principle (Don’t Repeat Yourself). Python is used throughout, even for configuration files and data models.

MTV Development Model

Django’s MTV model consists of:

Model : Handles data access, validation, behavior, and relationships.

Template : Manages presentation logic and renders data from models.

View : Processes user requests and returns responses.

Django Architecture

The main components are: urls.py: Entry point for URLs, mapping each URL to a view function or class. views.py: Handles requests, renders templates, and returns responses. models.py: Defines database models and ORM interactions. forms.py: Manages form rendering and validation (optional). templates/: Stores HTML templates rendered by views. admin.py: Provides a powerful admin interface with minimal code. settings.py: Configuration file (DEBUG flag, static files, etc.).

Popular Commercial Sites Using Django

Examples include Sohu Mail, Guokr, Douban, Yixiang, Yidou Online Cloud Office, Yirong, Kuaiwan Games, Jiujufang, Daibang, Qiqi, Zhihu, Fashion Space, Yuxi Board, DNSPod International, Xiaochufang, Beitai Kitchen, Wopus Q&A, Gudong, Shanbei, Webmaster Tools, Yidu Document Management, personal rental platforms, FIFA310 football data analysis, and many others.

Django Configuration Preparation

Prerequisites: pip, Python, Sublime Text, Anaconda environment installed.

System environment: OS: Windows 10 64‑bit IDE: Sublime + Anaconda Database: MySQL 5.6.17 Language: Python 3.5 Framework: Django 1.11 + Bootstrap Visualization tools: Highcharts, ECharts, Plotly, Bokeh (using ECharts)

Django Basic Installation Steps

1. Create a project named xmjc_analysis

Run the following commands in the E:\ drive:

Resulting files include settings.py, urls.py, wsgi.py, and __init__.py.

2. Create an app named analysis

Resulting app structure appears as shown.

3. Add the new app to INSTALLED_APPS in settings.py

4. Create the first view and URL

Modify analysis/views.py to define an index(request) function that returns an HttpResponse. Ensure the file starts with the UTF‑8 encoding declaration.

Update xmjc_analysis/urls.py to include the new view.

Run the development server to test:

Result shows the index page at http://127.0.0.1:8000/.

5. Pass parameters to the view

Modify the view to read GET parameters (e.g., ?name=admin) and display a personalized greeting.

Browser shows “Welcome admin”.

6. Configure a MySQL database (default is SQLite)

Update settings.py with MySQL connection parameters.

Modify __init__.py if needed.

Define models in analysis/models.py using Django ORM.

Register models in analysis/admin.py for admin display.

Run migrations to create tables.

Create a superuser (username: test, password: test123456).

Run the server ( python manage.py runserver) and log into the admin interface to manage data.

To display the admin interface in Chinese, modify settings.py accordingly.

Use Django’s QuerySet API in the shell to query and manipulate MySQL data.

Enter the shell with python manage.py shell and execute queries.

Create a new user record directly from the shell.

Other management methods are shown in the following screenshots.

8. Bulk import data

Import a name.txt file into the database using a custom script.

Script source (displayed as an image) reads the file and creates model instances.

Resulting data appears in the database.

— End of tutorial. Further deep‑dive topics will be covered in subsequent articles.

Source: Bai Ningchao (http://www.cnblogs.com/baiboy/p/django1.html)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPythonMVCdatabaseDjangoWeb DevelopmentTutorial
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.