Apa Itu Django?
Django adalah framework web Python yang high-level dan full-featured. Dibuat pada tahun 2005, Django mengikuti filosofi “batteries included”.
Mengapa Django?
- Batteries Included – Semua fitur built-in
- Admin Panel – Admin interface otomatis dari models
- ORM – Database abstraction yang powerful
- Security – Built-in protection terhadap XSS, CSRF, SQL injection
- Scalability – Digunakan oleh Instagram
- Documentation – Dokumentasi excellent
Roadmap Belajar Django
Level 1: Beginner
- Setup – Python, pip, virtualenv, django-admin startproject
- Project Structure – settings.py, urls.py, views.py, models.py
- Views and URLs – Function-based views, URL routing
- Templates – Django template language, template inheritance
- Models – Model definition, fields, migrations
- Admin – Register models, customize admin
- Forms – ModelForm, validation, CSRF
Level 2: Intermediate
- Class-Based Views – ListView, DetailView, CreateView, UpdateView, DeleteView
- ORM Advanced – QuerySet, filter, annotate, aggregate, F expressions
- Relationships – ForeignKey, ManyToMany, OneToOne
- Authentication – User model, login, logout, permissions
- Static and Media Files – collectstatic, file upload
- Middleware – Custom middleware
- Signals – pre_save, post_save, m2m_changed
Level 3: Advanced
- Django REST Framework – Serializers, ViewSets, Routers
- Testing – TestCase, Client, fixtures, factory_boy
- Caching – Cache framework, Redis, Memcached
- Async Views – async/await in Django 4+
- Celery – Background tasks, periodic tasks
- Channels – WebSockets, async consumers
Level 4: Expert
- Performance – Query optimization, select_related, prefetch_related
- Deployment – Gunicorn, Nginx, Docker, Heroku, AWS
- Security – HTTPS, HSTS, CSP, rate limiting
- Multi-tenancy – Shared schema, separate schema
Contoh Kode Django
# models.py
from django.db import models
class Kategori(models.Model):
nama = models.CharField(max_length=100)
slug = models.SlugField(unique=True)
def __str__(self):
return self.nama
class Produk(models.Model):
nama = models.CharField(max_length=200)
harga = models.DecimalField(max_digits=15, decimal_places=2)
kategori = models.ForeignKey(Kategori, on_delete=models.CASCADE)
aktif = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.nama
# views.py
from django.views.generic import ListView, DetailView
from .models import Produk
class ProdukListView(ListView):
model = Produk
template_name = 'produk/list.html'
context_object_name = 'produk_list'
paginate_by = 12
def get_queryset(self):
return Produk.objects.filter(aktif=True).select_related('kategori')
# admin.py
from django.contrib import admin
from .models import Produk, Kategori
@admin.register(Produk)
class ProdukAdmin(admin.ModelAdmin):
list_display = ['nama', 'harga', 'kategori', 'aktif', 'created_at']
list_filter = ['aktif', 'kategori']
search_fields = ['nama']
list_editable = ['aktif']
Tips Belajar Django
- Pelajari Python dulu – Django adalah framework Python
- Pahami MTV pattern – Model, Template, View
- Pelajari ORM – QuerySet, migrations, relationships
- Manfaatkan Admin panel – Fitur powerful Django
- Pelajari Django REST Framework – Untuk API development
- Baca Django Docs – docs.djangoproject.com
- Bangun project nyata – Blog, e-commerce, API
Tools yang Dibutuhkan
| Tool | Deskripsi |
|---|---|
| Python 3.x | Runtime Python |
| Pip and Virtualenv | Package manager and environment |
| Django | Framework web Python |
| PostgreSQL / MySQL | Database |
| VS Code / PyCharm | Code editor |
| Git | Version control |
Kesimpulan
Django adalah framework web Python yang full-featured dan production-ready. Dengan “batteries included” philosophy, Django memungkinkan developer membangun aplikasi web dengan cepat dan aman.
“Django makes it easier to build better web apps more quickly and with less code.” – Django Team




