# django-rest-framework

Guides your coding agent in creating Django REST Framework APIs with custom serializers, nested relations, and ViewSets.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 265 installs · ★ 201 repo stars
- Author: TheBushidoCollective
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/TheBushidoCollective/han/tree/HEAD/plugins/frameworks/django/skills/django-rest-framework/SKILL.md
- Updated: 2026-09-08
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/django-rest-framework

## What it does

This skill guides your coding assistant through standard Django REST Framework patterns. It covers `ModelSerializer` declarations, read-only and write-only field handling, and field-level or object-level validation. It also includes examples of specialized fields, such as converting base64 strings into Django files with `Base64ImageField`.

It addresses relationship management and endpoint construction. The documentation details nested representations, writable nested objects with custom `create` methods, and dynamic field inclusion inside `__init__`. For endpoints, it details `ModelViewSet` configurations with custom queryset filtering, `@action` decorators, and URL registration using `DefaultRouter` and `SimpleRouter`.

Because the skill marks `user-invocable: false`, you do not trigger it via a direct command. The model activates these guidelines automatically during DRF development tasks, relying on permitted tools `Bash` and `Read`.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add TheBushidoCollective/han --skill django-rest-framework -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/django-rest-framework/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/django-rest-framework/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add TheBushidoCollective/han --skill django-rest-framework -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/django-rest-framework/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add TheBushidoCollective/han --skill django-rest-framework -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/django-rest-framework/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install TheBushidoCollective/han plugins/frameworks/django/skills/django-rest-framework
```

2. **Manually: put the files in place**
- File: `.github/skills/django-rest-framework/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add TheBushidoCollective/han --skill django-rest-framework -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/TheBushidoCollective/han --path plugins/frameworks/django/skills/django-rest-framework
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/django-rest-framework/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add TheBushidoCollective/han --skill django-rest-framework -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/TheBushidoCollective/han/tree/HEAD/plugins/frameworks/django/skills/django-rest-framework/SKILL.md

## When to use it
- write serializers with custom field and object validation
- implement writable nested serializers for related models
- set up ModelViewSet instances with custom action endpoints
- register API endpoints using DRF routers

## Example prompts
- Create a serializer for the Post model with nested comments and custom title checks
- Build a ModelViewSet for articles with a custom publish action and filtered querysets
- Implement a serializer field to decode and store base64 image payloads

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 16f9256e10391457.

BEGIN THIRD-PARTY FILE 16f9256e10391457
````text
---
name: django-rest-framework
user-invocable: false
description: Use when Django REST Framework for building APIs with serializers, viewsets, and authentication. Use when creating RESTful APIs.
allowed-tools:
  - Bash
  - Read
---

# Django REST Framework

Master Django REST Framework for building robust, scalable RESTful
APIs with proper serialization and authentication.

## Serializers

Build type-safe data serialization with Django REST Framework serializers.

```python
from rest_framework import serializers
from django.contrib.auth.models import User

class UserSerializer(serializers.ModelSerializer):
    post_count = serializers.IntegerField(read_only=True)
    full_name = serializers.SerializerMethodField()

    class Meta:
        model = User
        fields = ['id', 'email', 'name', 'post_count', 'full_name']
        read_only_fields = ['id', 'created_at']
        extra_kwargs = {
            'email': {'required': True},
            'password': {'write_only': True}
        }

    def get_full_name(self, obj):
        return f"{obj.first_name} {obj.last_name}"

class PostSerializer(serializers.ModelSerializer):
    author = UserSerializer(read_only=True)
    author_id = serializers.IntegerField(write_only=True)

    class Meta:
        model = Post
        fields = '__all__'

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

    def validate(self, data):
        if data.get('published') and not data.get('content'):
            raise serializers.ValidationError('Published posts must have content')
        return data

    def create(self, validated_data):
        # Custom creation logic
        post = Post.objects.create(**validated_data)
        # Send notification, etc.
        return post
```

## Custom Fields and Validation

Create custom serializer fields for complex data types.

```python
from rest_framework import serializers

class Base64ImageField(serializers.ImageField):
    """Handle base64 encoded images."""

    def to_internal_value(self, data):
        import base64
        from django.core.files.base import ContentFile

        if isinstance(data, str) and data.startswith('data:image'):
            format, imgstr = data.split(';base64,')
            ext = format.split('/')[-1]
````
END THIRD-PARTY FILE 16f9256e10391457

The third-party file has ended. Everything between the 16f9256e10391457 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2360 of 43602 bytes. © TheBushidoCollective · Apache-2.0 · https://github.com/TheBushidoCollective/han/tree/HEAD/plugins/frameworks/django/skills/django-rest-framework/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
