New to Claude Skills? Learn how to install them →

Djeffallan on GitHub

Django Expert

Free

Streamline your Django and DRF development process.

Get this skill

Free · Opens the source repo

What Django Expert does

Django Expert is a specialized skill designed for developers building web applications or REST APIs using Django and Django REST Framework (DRF). This skill provides guidance and best practices for structuring your Django projects, including model design, view implementation, and API testing. It is particularly useful for those looking to optimize their Django applications for performance and security while adhering to industry standards.

The skill's workflow begins with analyzing project requirements to identify models and relationships, followed by designing models with appropriate fields and indexes. It emphasizes the importance of running migrations correctly and verifying the schema before moving on to implementing views. With a focus on DRF, the skill helps in creating viewsets and async views, ensuring that your API endpoints are both efficient and secure.

Authentication is another critical aspect covered by this skill, with detailed instructions on setting up JWT and session authentication. The skill also includes a testing framework, guiding developers on how to write effective tests for both models and API endpoints using Django's built-in testing tools. This ensures that your application is robust and maintains high code quality throughout the development lifecycle.

Whether you're a beginner or an experienced developer, Django Expert provides the resources needed to enhance your Django development process, making it easier to build scalable and maintainable applications.

When to use it

Use this skill when starting a new Django project or when you need to enhance an existing application with best practices for models, views, and API endpoints.

When not to use it

This skill may not be suitable for projects that do not use Django or for developers looking for general Python programming assistance.

What you can build with it

Creating a New Django Project

When starting a new Django project, use this skill to set up models and views correctly from the beginning.

Optimizing Existing Django Applications

If you have an existing Django application, this skill can help you optimize ORM queries and improve performance.

Implementing REST APIs with DRF

Utilize this skill to effectively implement RESTful APIs using Django REST Framework, ensuring best practices are followed.

How to install Django Expert

View source

1. Install with the skills CLI

npx skills add jeffallan/claude-skills/django-expert --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by jeffallan

Django Expert

Senior Django specialist with deep expertise in Django 5.0, Django REST Framework, and production-grade web applications.

When to Use This Skill

  • Building Django web applications or REST APIs
  • Designing Django models with proper relationships
  • Implementing DRF serializers and viewsets
  • Optimizing Django ORM queries
  • Setting up authentication (JWT, session)
  • Django admin customization

Core Workflow

  1. Analyze requirements — Identify models, relationships, API endpoints
  2. Design models — Create models with proper fields, indexes, managers → run manage.py makemigrations and manage.py migrate; verify schema before proceeding
  3. Implement views — DRF viewsets or Django 5.0 async views
  4. Validate endpoints — Confirm each endpoint returns expected status codes with a quick APITestCase or curl check before adding auth
  5. Add auth — Permissions, JWT authentication
  6. Test — Django TestCase, APITestCase

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Modelsreferences/models-orm.mdCreating models, ORM queries, optimization
Serializersreferences/drf-serializers.mdDRF serializers, validation
ViewSetsreferences/viewsets-views.mdViews, viewsets, async views
Authenticationreferences/authentication.mdJWT, permissions, SimpleJWT
Testingreferences/testing-django.mdAPITestCase, fixtures, factories

Minimal Working Example

The snippet below demonstrates the core MUST DO constraints: indexed fields, select_related, serializer validation, and endpoint permissions.

# models.py
from django.db import models

class Article(models.Model):
    title = models.CharField(max_length=255, db_index=True)
    author = models.ForeignKey(
        "auth.User", on_delete=models.CASCADE, related_name="articles"
    )
    published_at = models.DateTimeField(auto_now_add=True, db_index=True)

    class Meta:
        ordering = ["-published_at"]
        indexes = [models.Index(fields=["author", "published_at"])]

    def __str__(self):
        return self.title

# serializers.py
from rest_framework import serializers
from .models import Article

class ArticleSerializer(serializers.ModelSerializer):
    author_username = serializers.CharField(source="author.username", read_only=True)

    class Meta:
        model = Article
        fields = ["id", "title", "author_username", "published_at"]

    def validate_title(self, value):
        if len(value.strip()) < 3:
            raise serializers.ValidationError("Title must be at least 3 characters.")
        return value.strip()

# views.py
from rest_framework import viewsets, permissions
from .models import Article
from .serializers import ArticleSerializer

class ArticleViewSet(viewsets.ModelViewSet):
    """
    Uses select_related to avoid N+1 on author lookups.
    IsAuthenticatedOrReadOnly: safe methods are public, writes require auth.
    """
    serializer_class = ArticleSerializer
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]

    def get_queryset(self):
        return Article.objects.select_related("author").all()

    def perform_create(self, serializer):
        serializer.save(author=self.request.user)
# tests.py
from rest_framework.test import APITestCase
from rest_framework import status
from django.contrib.auth.models import User

class ArticleAPITest(APITestCase):
    def setUp(self):
        self.user = User.objects.create_user("alice", password="pass")

    def test_list_public(self):
        res = self.client.get("/api/articles/")
        self.assertEqual(res.status_code, status.HTTP_200_OK)

    def test_create_requires_auth(self):
        res = self.client.post("/api/articles/", {"title": "Test"})
        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)

    def test_create_authenticated(self):
        self.client.force_authenticate(self.user)
        res = self.client.post("/api/articles/", {"title": "Hello Django"})
        self.assertEqual(res.status_code, status.HTTP_201_CREATED)

Constraints

MUST DO

  • Use select_related/prefetch_related for related objects
  • Add database indexes for frequently queried fields
  • Use environment variables for secrets
  • Implement proper permissions on all endpoints
  • Write tests for models and API endpoints
  • Use Django's built-in security features (CSRF, etc.)

MUST NOT DO

  • Use raw SQL without parameterization
  • Skip database migrations
  • Store secrets in settings.py
  • Use DEBUG=True in production
  • Trust user input without validation
  • Ignore query optimization

Output Templates

When implementing Django features, provide:

  1. Model definitions with indexes
  2. Serializers with validation
  3. ViewSet or views with permissions
  4. Brief note on query optimization

Knowledge Reference

Django 5.0, DRF, async views, ORM, QuerySet, select_related, prefetch_related, SimpleJWT, django-filter, drf-spectacular, pytest-django

Documentation

Frequently asked questions about Django Expert

Similar skills