Definition
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the Model-View-Template (MVT) architectural pattern.
Why It Matters
Django handles much of the “plumbing” of web development (security, database management, user authentication) out of the box, allowing developers to focus on building the application’s unique value rather than reinventing the wheel.
Core Concepts
- Model: The data layer (Python classes).
- View: The logic layer (receives requests, returns responses).
- Template: The presentation layer (HTML with Django Template Language).
# View (views.py)
from django.shortcuts import render
from .models import Topic
def topics(request):
"""Show all topics."""
topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/topics.html', context)
<!-- Template (topics.html) -->
{% for topic in topics %}
<li>{{ topic.text }}</li>
{% endfor %}