03. Django Basic - Cơ Bản Django

Mục Tiêu Module

Học các khái niệm cơ bản của Django framework để xây dựng web applications.

Danh Sách Bài Học

1. Giới Thiệu Django

  • Django là gì?
  • MVT (Model-View-Template) pattern
  • Django vs Flask vs FastAPI
  • Khi nào nên dùng Django
  • Django ecosystem

2. Django Installation và Setup

  • Cài đặt Django
  • Tạo project với django-admin
  • Cấu trúc Django project
  • manage.py commands
  • Development server

3. Django Apps

  • Apps là gì?
  • Tạo app với startapp
  • Đăng ký apps trong INSTALLED_APPS
  • App structure
  • Reusable apps

4. URLs và Views

  • URL routing
  • URLconf (urls.py)
  • path() và re_path()
  • URL parameters
  • Function-based views
  • HttpRequest và HttpResponse

5. Templates

  • Template engine
  • Template syntax ({{ }}, {% %})
  • Template variables
  • Template filters
  • Template tags
  • Template inheritance (extends, block)
  • include templates

6. Static Files

  • STATIC_URL và STATIC_ROOT
  • Organizing static files (CSS, JS, images)
  • {% load static %}
  • {% static %} tag
  • collectstatic command

7. Models Cơ Bản

  • ORM concepts
  • Defining models
  • Field types (CharField, IntegerField, etc.)
  • Field options (max_length, null, blank, default)
  • Meta options
  • str method

8. Database Migrations

  • makemigrations command
  • migrate command
  • Migration files
  • showmigrations
  • Rolling back migrations
  • Custom migrations

9. Django Admin

  • Automatic admin interface
  • Creating superuser
  • Registering models
  • Admin customization (list_display, search_fields)
  • ModelAdmin class
  • Admin actions

10. QuerySets

  • Manager và QuerySets
  • Creating objects (create, save)
  • Retrieving objects (all, get, filter)
  • Field lookups (exact, iexact, contains, gt, lt)
  • Ordering results
  • Limiting results

11. CRUD Operations

  • Create (INSERT)
  • Read (SELECT)
  • Update (UPDATE)
  • Delete (DELETE)
  • get_or_create()
  • update_or_create()

12. Forms

  • Django Forms
  • Form fields
  • Rendering forms
  • Form validation
  • Cleaned data
  • Error handling

13. Model Forms

  • ModelForm class
  • Automatic form generation
  • fields và exclude
  • Widgets
  • Saving ModelForms

14. Authentication Basics

  • User model
  • Login và logout views
  • login_required decorator
  • User registration
  • Password change
  • Authentication backends

15. Sessions và Cookies

  • Session framework
  • Setting session data
  • Reading session data
  • Session configuration
  • Cookie handling

16. Messages Framework

  • Message levels (debug, info, success, warning, error)
  • Adding messages
  • Displaying messages
  • Message tags

17. Middleware

  • Middleware là gì?
  • MIDDLEWARE setting
  • Request/response cycle
  • Common middleware
  • Custom middleware basics

18. Django Settings

  • settings.py overview
  • DEBUG mode
  • ALLOWED_HOSTS
  • DATABASES configuration
  • SECRET_KEY
  • Environment variables với python-decouple

19. Generic Views

  • TemplateView
  • ListView
  • DetailView
  • CreateView
  • UpdateView
  • DeleteView

20. Testing Basics

  • Django TestCase
  • Writing test cases
  • Testing views
  • Testing models
  • Test client
  • Running tests

Prerequisites

  • ✅ Hoàn thành Module 01: Python Basic
  • ✅ Hoàn thành Module 02: Python Advanced (khuyến nghị)
  • Hiểu cơ bản về HTML/CSS
  • Hiểu cơ bản về databases

Thời Gian Học

  • Ước tính: 3-4 tuần
  • Thời lượng mỗi bài: 60-90 phút
  • Thực hành: 2-3 giờ/ngày

Tài Nguyên Tham Khảo

Projects

Mini Projects

  1. Blog: Simple blog với posts và comments
  2. Todo List: Task management app
  3. Contact Form: Form handling với email

Final Project

Personal Portfolio Website:

  • Multiple pages
  • Admin interface
  • Contact form
  • Static files
  • Database models
  • Authentication

Bài Tập

Mỗi bài học sẽ có:

  • ✍️ Exercises: 5-7 bài tập thực hành
  • 🔨 Hands-on Labs: Build small features
  • 📝 Quiz: Kiểm tra kiến thức
  • 🎯 Challenge: Bài tập nâng cao

Module Tiếp Theo

04-django-advance - Học các tính năng Django nâng cao cho production applications.