django-cbv-patterns
БесплатноБез исполняемых скриптовНе проверенUse when Django Class-Based Views for building modular, reusable views. Use when creating CRUD operations and complex view logic.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
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.
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.
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin, PermissionRequiredMixin
from django.views.generic import CreateView, UpdateView
class PostCreateView(LoginRequiredMixin, CreateView):
model = Post
fields = ['title', 'content']
login_url = '/login/'
redirect_field_name = 'next'
class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Post
fields = ['title', 'content']
def test_func(self):
post = self.get_object()
return self.request.user == post.author
def handle_no_permission(self):
# Custom handling when test fails
messages.error(self.request, 'You can only edit your own posts')
return redirect('post-list')
class AdminPostListView(PermissionRequiredMixin, ListView):
model = Post
permission_required = 'posts.view_post'
raise_exception = True # Return 403 instead of redirect
Custom Mixins
Create reusable mixins for common patterns.
from django.views.generic import View
from django.shortcuts import redirect
from django.contrib import messages
class AuthorRequiredMixin:
"""Ensure the current user is the object's author."""
def dispatch(self, request, *args, **kwargs):
obj = self.get_object()
if obj.author != request.user:
messages.error(request, 'You do not have permission')
return redirect('post-list')
return super().dispatch(request, *args, **kwargs)
class FormMessageMixin:
"""Add success messages to form views."""
success_message = ''
def form_valid(self, form):
response = super().form_valid(form)
if self.success_message:
messages.success(self.request, self.success_message)
return response
class AjaxableResponseMixin:
"""Handle AJAX requests differently."""
def form_valid(self, form):
if self.request.is_ajax():
data = {
'pk': form.instance.pk,
'success': True
}
return JsonResponse(data)
return super().form_valid(form)
def form_invalid(self, form):
if self.request.is_ajax():
return JsonResponse(form.errors, status=400)
return super().form_invalid(form)
# Usage
class PostUpdateView(LoginRequiredMixin, AuthorRequiredMixin, FormMessageMixin, UpdateView):
model = Post
fields = ['title', 'content']
success_message = 'Post updated successfully'
Method Resolution Order (MRO)
Understand how Django resolves methods in CBVs.
# MRO matters! Order from left to right
class PostUpdateView(
LoginRequiredMixin, # Check login first
AuthorRequiredMixin, # Then check authorship
FormMessageMixin, # Add messages
UpdateView # Base view last
):
model = Post
fields = ['title', 'content']
# View the MRO
print(PostUpdateView.__mro__)
# Bad example - wrong order
class BadPostUpdateView(
UpdateView, # Base view first - wrong!
LoginRequiredMixin,
Aut
Установить django-cbv-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadFAQ
Что делает скилл django-cbv-patterns?
Use when Django Class-Based Views for building modular, reusable views. Use when creating CRUD operations and complex view logic.
Как установить скилл django-cbv-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл django-cbv-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic