Django Learning Guide (Beginner to Intermediate)
1. Introduction to Django
- Django is a high-level Python web framework that encourages rapid development and clean,
pragmatic design.
- Follows the MVT (Model-View-Template) architectural pattern.
2. Environment Setup
- Install Python, pip, and virtualenv.
- Create a virtual environment: python -m venv env
- Install Django: pip install django
3. Creating a Django Project
- django-admin startproject projectname
- Run the server: python manage.py runserver
4. Django Project Structure
- manage.py: command-line utility
- projectname/: settings, URLs, WSGI/ASGI
- apps/: reusable Django components
5. Creating an App
- python manage.py startapp appname
- Add app to INSTALLED_APPS in settings.py
6. Models (Database Layer)
- Define models in models.py
- Run makemigrations and migrate to apply changes
7. Admin Interface
- Register models in admin.py
- Create superuser: python manage.py createsuperuser
8. Views and URLs
- Define views in views.py (function/class-based)
- Map URLs in urls.py using path() or re_path()
9. Templates (Frontend)
- Use HTML + Django Template Language (DTL)
- Load templates via render(request, 'template.html', context)
10. Static and Media Files
- static/: CSS, JS, images
- media/: user-uploaded files
- Configure STATIC_URL and MEDIA_URL
11. Forms
- Built-in forms (forms.Form, forms.ModelForm)
- CSRF protection, form validation, custom widgets
12. User Authentication
- Built-in auth system: login, logout, register
- User model customization (AbstractUser)
13. Middleware
- Process request/response globally
- Custom middleware for logging, authentication
14. Class-Based Views (CBV)
- TemplateView, ListView, DetailView, CreateView, etc.
- URL routing with as_view()
15. Django REST Framework (Intro)
- Build APIs using serializers, viewsets, routers
16. Intermediate Features
- Signals: decoupled logic for events
- Caching: improve performance
- Testing: unit tests with Django's test framework
- Pagination: for large querysets
17. Deployment (Basic)
- Use Gunicorn + Nginx or Heroku for deployment
- Configure ALLOWED_HOSTS, DEBUG=False, static/media handling
18. Best Practices
- Use environment variables for secrets
- Modularize settings (dev, prod)
- Use class-based views and DRY principles
Resources:
- https://docs.djangoproject.com/
- https://www.djangoproject.com/start/
- https://djangoproject.com/community/
Happy Learning!