Use when Django Class-Based Views for building modular, reusable views. Use when creating CRUD operations and complex view logic.
View on GitHubTheBushidoCollective/han
jutsu-django
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-django/skills/django-cbv-patterns/SKILL.md -a claude-code --skill django-cbv-patternsInstallation paths:
.claude/skills/django-cbv-patterns/# Django Class-Based Views
Master Django Class-Based Views for building modular, reusable view
logic with proper separation of concerns.
## Generic Views
Use Django's built-in generic views for common patterns.
```python
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from django.urls import reverse_lazy
class PostListView(ListView):
model = Post
template_name = 'posts/list.html'
context_object_name = 'posts'
paginate_by = 10
ordering = ['-created_at']
def get_queryset(self):
queryset = super().get_queryset()
# Only show published posts
return queryset.filter(published=True).select_related('author')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['total_posts'] = self.get_queryset().count()
return context
class PostDetailView(DetailView):
model = Post
template_name = 'posts/detail.html'
context_object_name = 'post'
def get_queryset(self):
return super().get_queryset().select_related('author').prefetch_related('comments')
class PostCreateView(CreateView):
model = Post
fields = ['title', 'content', 'published']
template_name = 'posts/create.html'
success_url = reverse_lazy('post-list')
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
class PostUpdateView(UpdateView):
model = Post
fields = ['title', 'content', 'published']
template_name = 'posts/update.html'
def get_success_url(self):
return reverse_lazy('post-detail', kwargs={'pk': self.object.pk})
class PostDeleteView(DeleteView):
model = Post
template_name = 'posts/confirm_delete.html'
success_url = reverse_lazy('post-list')
```
## Built-in Mixins
Leverage Django's built-in mixins for common functionality.
```python
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin, P