.agents/skills/django/SKILL.md
Django batteries-included Python framework. Covers models, views, templates, ORM, and admin. Use when building full-featured Python web applications. USE WHEN: user mentions "django", "django orm", "django admin", "django templates", asks about "python cms", "django rest framework", "drf", "django models", "django migrations", "django channels", "django forms" DO NOT USE FOR: FastAPI projects - use `fastapi` instead, Flask projects - use `flask` instead, async-first Python APIs, microservices without admin panel
npx skillsauth add d-subrahmanyam/deno-fresh-microservices djangoInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Full Reference: See advanced.md for Django Channels setup, WebSocket consumers, JWT authentication middleware, broadcasting from views, room management, and WebSocket testing.
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:djangofor comprehensive documentation.
from django.db import models
class User(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(unique=True)
created_at = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.name
from django.views.generic import ListView, DetailView, CreateView
from django.urls import reverse_lazy
class UserListView(ListView):
model = User
template_name = 'users/list.html'
context_object_name = 'users'
paginate_by = 20
class UserDetailView(DetailView):
model = User
template_name = 'users/detail.html'
class UserCreateView(CreateView):
model = User
fields = ['name', 'email']
success_url = reverse_lazy('user-list')
from rest_framework import viewsets, serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['id', 'name', 'email', 'created_at']
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
myproject/
├── manage.py
├── myproject/
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── users/
├── models.py
├── views.py
├── urls.py
└── admin.py
| Anti-Pattern | Why It's Bad | Solution |
|--------------|--------------|----------|
| N+1 queries | Slow performance | Use select_related() and prefetch_related() |
| No index on frequently queried fields | Slow queries | Add db_index=True to model fields |
| Using .filter() in loops | Multiple DB hits | Use .filter(id__in=list) |
| Storing sensitive data in settings.py | Security risk | Use environment variables |
| Missing CSRF protection | XSS vulnerability | Keep CsrfViewMiddleware enabled |
| Fat models | Hard to test | Move business logic to services |
| Problem | Diagnosis | Fix |
|---------|-----------|-----|
| "No such table" error | Migrations not applied | Run python manage.py migrate |
| Static files not loading | STATIC_URL misconfigured | Run collectstatic in production |
| CSRF verification failed | Missing CSRF token | Add {% csrf_token %} to forms |
| "OperationalError: database is locked" | SQLite concurrency | Use PostgreSQL in production |
| Circular import errors | Models importing each other | Use get_model() or string references |
| Slow admin interface | No list_select_related | Add list_select_related to ModelAdmin |
# settings/production.py
DEBUG = False
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')
SECRET_KEY = env('SECRET_KEY')
# Security headers
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = 'DENY'
# Session security
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
CSRF_COOKIE_SECURE = True
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': env('REDIS_URL'),
}
}
# Usage
from django.views.decorators.cache import cache_page
@cache_page(60 * 15) # 15 minutes
def my_view(request):
...
from django.http import JsonResponse
from django.db import connection
def health_check(request):
return JsonResponse({'status': 'healthy'})
def ready_check(request):
try:
connection.ensure_connection()
return JsonResponse({'status': 'ready', 'database': 'connected'})
except Exception as e:
return JsonResponse({'status': 'not ready', 'error': str(e)}, status=503)
# gunicorn.conf.py
import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'uvicorn.workers.UvicornWorker' # For async
bind = '0.0.0.0:8000'
max_requests = 1000
timeout = 30
import pytest
from django.test import Client
@pytest.fixture
def authenticated_client(django_user_model):
user = django_user_model.objects.create_user(
username='test', password='test123'
)
client = Client()
client.force_login(user)
return client
@pytest.mark.django_db
class TestUserAPI:
def test_create_user(self, api_client):
response = api_client.post('/api/users/', {
'name': 'John', 'email': '[email protected]'
}, content_type='application/json')
assert response.status_code == 201
| Metric | Target | |--------|--------| | Response time (p99) | < 200ms | | Error rate (5xx) | < 0.1% | | Database connections | < pool size | | Cache hit ratio | > 80% |
development
Guidelines for building high-performance APIs with Fastify and TypeScript, covering validation, Prisma integration, and testing best practices
development
FastAPI modern Python web framework. Covers routing, Pydantic models, dependency injection, and async support. Use when building Python APIs. USE WHEN: user mentions "fastapi", "pydantic", "async python api", "python rest api", asks about "dependency injection python", "python openapi", "python swagger", "async endpoints", "python api validation", "fastapi middleware" DO NOT USE FOR: Django apps - use `django` instead, Flask apps - use `flask` instead, synchronous Python APIs without type hints, GraphQL-only APIs
tools
FastAPI integration testing specialist. Covers synchronous TestClient, async httpx AsyncClient, dependency injection overrides, auth testing (JWT, OAuth2, API keys), WebSocket testing, file uploads, background tasks, middleware testing, and HTTP mocking with respx, responses, and pytest-httpserver. USE WHEN: user mentions "FastAPI test", "TestClient", "httpx async test", "dependency override test", "respx mock", asks about testing FastAPI endpoints, authentication in tests, or HTTP client mocking. DO NOT USE FOR: Django - use `pytest-django`; pytest internals - use `pytest`; Container infrastructure - use `testcontainers-python`
development
Expert in FastAPI Python development with best practices for APIs and async operations