django
Skill4 starsChanged 7 months agoMITView on GitHub
Load this file when working on a Django project. Use alongside all skills/common/ files. Rule: Always set AUTH_USER_MODEL = "users.User" in settings. Never use from django.contrib.auth.models import User directly in app code — always get_user_model(). Django views should be thin. Business logic goes in services.py:
- Reads credentials
10 other projects use a version of this.
Adopted by
Most recently taken up by
- conjure-3301/skillstheir own version, first seen Aug 17, 2026
- Mariatta/claude-skillstheir own version, first seen Aug 7, 2026
- imankulov/skillstheir own version, first seen Aug 2, 2026
- wsvincent/django-skillstheir own version, first seen Aug 2, 2026
- gingerminds/claude-skillstheir own version, first seen Jul 24, 2026
- youlaitech/youlai-skillstheir own version, first seen Jul 14, 2026
Used with
Projects with it also use vue.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JetBrainsSkillvue
Vue 3 Composition API, script setup macros, reactivity system, and built-in components. Use when writing Vue SFCs, defineProps/defineEmits/defineModel, watchers, or using Transition/Teleport/Suspense/KeepAlive.
Also in 3 projects that use this
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- microsoft/debugpy★ 2.5ksame name
- youlaitech/youlai-skills★ 56same name
- wsvincent/django-skills★ 36same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- dekoza/oh-my-slop★ 4same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- gingerminds/claude-skills★ 2same name
- imankulov/skills★ 2same name
- Mariatta/claude-skills★ 2same name
- conjure-3301/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/python-core.mdcCursor rule
- .cursor/rules/python-security.mdcCursor rule
- .cursor/rules/python-testing.mdcCursor rule
- llms.txtllms.txt
- python-standardsSkill
- drfSkill
- fastapiSkill
- flaskSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. 0 are common, 3 are distinctive, and 14 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 152
Rule: Always set AUTH_USER_MODEL = "users.User" in settings.
- Very specific: line 222
Use TestCase (wraps each test in a transaction, rolled back after).
- Distinctive: line 340
All Django models follow this strict ordering inside the class body:
- Very specific: line 409
Always use TextChoices or IntegerChoices for new models.
- Very specific: line 411
Never use bare strings for status comparisons: use Order.Status.PENDING, not "pending".
- Very specific: line 447
Never define application-specific routes in config/urls.py.
- Very specific: line 448
Always set app_name for reversible URL namespaces (reverse("posts:detail", ...)).
- Very specific: line 469
Keep all templates in the project-level templates/ directory unless building a reusable app.
- Very specific: line 496
Always name {% endblock %} tags: {% endblock content %} not {% endblock %}.
- Very specific: line 498
No space around . for attribute access or | for filters: {{ user.name|lower }} not {{ user.name | lower }}.
- Very specific: line 499
Never indent top-level {% block %} tags inside {% extends %} templates.
- Very specific: line 522
Always use django.contrib.staticfiles — never hardcode /static/ paths in templates.
- Distinctive: line 570
All user-visible strings must be wrapped for translation:
- Very specific: line 590
Use gettext_lazy (_) in model fields, Meta, forms, serializers — evaluated lazily.
- Very specific: line 591
Use gettext in views and services — evaluated immediately (request context available).
- Distinctive: line 592
Never: use f-strings for strings that may need translation — format after wrapping:
- Very specific: line 600
Run makemessages and compilemessages in CI.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Django Skill
Load this file when working on a Django project. Use alongside all
skills/common/files.
Stack
| Layer | Library |
| Framework | Django 5.x |
| ORM | Django ORM (built-in) |
| Migrations | Django migrations |
| Settings | django-environ or pydantic-settings |
| Static Files | WhiteNoise (prod) |
| Task Queue | Celery + Redis |
| Caching | django-redis |
| Admin | Django Admin (with django-jazzmin for UI) |
Project Structure
myproject/
├── config/
│ ├── settings/
│ │ ├── base.py ← Shared settings
│ │ ├── development.py ← Dev overrides
│ │ └── production.py ← Prod overrides
│ ├── urls.py
│ ├── wsgi.py
│ └── asgi.py
├── apps/
│ ├── users/
│ │ ├── models.py
│ │ ├── views.py
│ │ ├── serializers.py ← (if using DRF)
│ │ ├── services.py
│ │ ├── repositories.py
│ │ ├── urls.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── migrations/
│ │ └── tests/
│ │ ├── test_models.py
│ │ ├── test_views.py
│ │ └── test_services.py
│ └── core/
│ ├── models.py ← Abstract base models
│ └── exceptions.py
├── manage.py
└── pyproject.tomlSettings Pattern (Split by Environment)
# config/settings/base.py
from pathlib import Path
import environ
env = environ.Env()
BASE_DIR = Path(__file__).resolve().parent.parent.parent
environ.Env.read_env(BASE_DIR / ".env")
SECRET_KEY = env("SECRET_KEY")
DEBUG = env.bool("DEBUG", default=False)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
DATABASES = {
"default": env.db("DATABASE_URL")
}
INSTALLED_APPS = [
# Django built-ins
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Third party
"rest_framework",
"corsheaders",
# Local
"apps.users",
"apps.core",
]Abstract Base Model
# apps/core/models.py
from django.db import models
import uuid
class TimeStampedModel(models.Model):
"""Abstract model that provides created_at and updated_at fields."""
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
class UUIDModel(models.Model):
"""Abstract model with UUID public identifier."""
public_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
class Meta:
abstract = TrueModel Standards
# apps/users/models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
from apps.core.models import TimeStampedModel, UUIDModel
class User(AbstractUser, TimeStampedModel, UUIDModel):
"""Custom user model — always use AbstractUser, never User directly."""
email = models.EmailField(unique=True)
USERNAME_FIELD = "email"
REQUIRED_FIELDS = ["username"]
class Meta:
db_table = "users"
ordering = ["-created_at"]
indexes = [
models.Index(fields=["email"], name="ix_users_email"),
]
verbose_name = "User"
verbose_name_plural = "Users"
def __str__(self) -> str:
return self.emailRule: Always set AUTH_USER_MODEL = "users.User" in settings. Never use from django.contrib.auth.models import User directly in app code — always get_user_model().
Service Layer
Django views should be thin. Business logic goes in services.py:
# apps/users/services.py
from django.db import transaction
from apps.users.models import User
from apps.core.exceptions import ConflictError
class UserService:
@staticmethod
@transaction.atomic
def create_user(email: str, password: str, name: str) -> User:
"""Create and activate a new user account."""
if User.objects.filter(email=email).exists():
raise ConflictError(f"User with email '{email}' already exists.")
user = User.objects.create_user(
username=email, email=email, password=password, first_name=name
)
return userAdmin Registration
# apps/users/admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from apps.users.models import User
@admin.register(User)
class UserAdmin(BaseUserAdmin):
list_display = ["email", "name", "is_active", "created_at"]
list_filter = ["is_active", "is_staff"]
search_fields = ["email", "first_name"]
ordering = ["-created_at"]
readonly_fields = ["public_id", "created_at", "updated_at"]Django Tests
# apps/users/tests/test_services.py
from django.test import TestCase
from apps.users.services import UserService
from apps.core.exceptions import ConflictError
class TestUserService(TestCase):
def test_create_user_success(self):
user = UserService.create_user(
email="test@example.com", password="SecurePass1!", name="Test"
)
self.assertEqual(user.email, "test@example.com")
self.assertTrue(user.is_active)
def test_create_user_duplicate_email_raises_conflict(self):
UserService.create_user(email="dup@example.com", password="Pass1!", name="A")
with self.assertRaises(ConflictError):
UserService.create_user(email="dup@example.com", password="Pass2!", name="B")Use TestCase (wraps each test in a transaction, rolled back after). Use TransactionTestCase only when testing signals or raw transactions.
Management Commands
# apps/users/management/commands/seed_admin.py
from django.core.management.base import BaseCommand
from apps.users.models import User
class Command(BaseCommand):
help = "Create default admin user for development"
def handle(self, *args, **options):
if not User.objects.filter(email="admin@example.com").exists():
User.objects.create_superuser(
username="admin", email="admin@example.com", password="changeme"
)
self.stdout.write(self.style.SUCCESS("Admin user created."))Fat Models & Chainable Custom Managers
Business logic belongs on the model or its manager — not in views or services. Thin views, fat models. Small, named methods are easier to test and reuse.
# apps/posts/models.py
import datetime
from django.db import models
from django.db.models import QuerySet
class PostQuerySet(QuerySet):
"""Chainable queryset methods — available on both manager and queryset."""
def live(self) -> "PostQuerySet":
"""Filter to posts that are published and whose publish date has passed."""
now = datetime.datetime.now(tz=datetime.timezone.utc)
return self.filter(date_published__lte=now, status=Post.Status.PUBLISHED)
def by_author(self, author_id: int) -> "PostQuerySet":
"""Filter to posts by a specific author."""
return self.filter(author_id=author_id)
class PostManager(models.Manager):
"""Default manager — returns PostQuerySet so all custom methods chain."""
def get_queryset(self) -> PostQuerySet:
return PostQuerySet(self.model, using=self._db)
class Post(models.Model):
"""Blog post with lifecycle management."""
class Status(models.TextChoices):
DRAFT = "draft", "Draft"
PUBLISHED = "published", "Published"
ARCHIVED = "archived", "Archived"
title = models.CharField(max_length=255)
body = models.TextField()
status = models.CharField(max_length=20, choices=Status, default=Status.DRAFT)
author = models.ForeignKey(
"users.User", on_delete=models.PROTECT, related_name="posts"
)
date_published = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
objects = PostManager()
class Meta:
ordering = ["-date_published"]
indexes = [models.Index(fields=["status", "date_published"])]
def __str__(self) -> str:
return self.title
def save(self, *args, **kwargs) -> None: # type: ignore[override]
"""Auto-set date_published when status transitions to PUBLISHED."""
if self.status == self.Status.PUBLISHED and self.date_published is None:
self.date_published = datetime.datetime.now(tz=datetime.timezone.utc)
super().save(*args, **kwargs)
def get_absolute_url(self) -> str:
"""Return canonical URL for this post."""
from django.urls import reverse
return reverse("posts:detail", kwargs={"pk": self.pk})
def is_live(self) -> bool:
"""Return True if this post is publicly visible right now."""
now = datetime.datetime.now(tz=datetime.timezone.utc)
return (
self.status == self.Status.PUBLISHED
and self.date_published is not None
and self.date_published <= now
)Chaining works on both manager and queryset:
Post.objects.live() # direct on manager
Post.objects.by_author(5).live() # chained on queryset
Post.objects.filter(title__icontains="AI").live() # mixedRule: Custom logic that filters, annotates, or queries a model goes in a custom QuerySet
method. Never repeat the same .filter(...) call in two different views.
Canonical Model Inner Class Ordering
All Django models follow this strict ordering inside the class body:
class MyModel(models.Model):
# 1. All database field definitions
name = models.CharField(max_length=100)
status = models.CharField(max_length=20, choices=Status)
# 2. Custom manager attributes (replaces default `objects`)
objects = MyModelManager()
# 3. class Meta (one blank line after fields)
class Meta:
ordering = ["name"]
verbose_name = "My Model"
verbose_name_plural = "My Models"
# 4. Python magic methods (__str__, __repr__, __eq__, etc.)
def __str__(self) -> str:
return self.name
# 5. def save() override (if any)
def save(self, *args, **kwargs) -> None:
super().save(*args, **kwargs)
# 6. def get_absolute_url() (if any)
def get_absolute_url(self) -> str:
...
# 7. All custom methods (business logic)
def is_active(self) -> bool:
...Choices: Inline Constants vs TextChoices
Preferred — TextChoices enum (Django 3.0+):
class Order(models.Model):
class Status(models.TextChoices):
PENDING = "pending", "Pending"
PROCESSING = "processing", "Processing"
SHIPPED = "shipped", "Shipped"
DELIVERED = "delivered", "Delivered"
CANCELLED = "cancelled", "Cancelled"
status = models.CharField(
max_length=20,
choices=Status,
default=Status.PENDING,
)Acceptable — uppercase class attributes (legacy / external value constraints):
class Order(models.Model):
STATUS_PENDING = "pending"
STATUS_PROCESSING = "processing"
STATUS_CHOICES = {
STATUS_PENDING: "Pending",
STATUS_PROCESSING: "Processing",
}
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default=STATUS_PENDING)Rules:
- Always use
TextChoicesorIntegerChoicesfor new models. - Choice constant names are UPPER_CASE — always.
- Never use bare strings for status comparisons: use
Order.Status.PENDING, not"pending".
URLconf Rules
Project URLconf (config/urls.py) — delegate, never define routes here:
# config/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("api/v1/users/", include("apps.users.urls")),
path("api/v1/posts/", include("apps.posts.urls")),
path("api/v1/orders/", include("apps.orders.urls")),
]App URLconf (apps/posts/urls.py) — own all routes for that app:
# apps/posts/urls.py
from django.urls import path
from apps.posts import views
app_name = "posts"
urlpatterns = [
path("", views.PostListView.as_view(), name="list"),
path("<int:pk>/", views.PostDetailView.as_view(), name="detail"),
path("create/", views.PostCreateView.as_view(), name="create"),
]Rules:
- Never define application-specific routes in
config/urls.py. - Always set
app_namefor reversible URL namespaces (reverse("posts:detail", ...)). - Separate URLconfs for separate environments if needed (e.g.,
urls/dev.pyadds debug-toolbar).
Template Naming & Organization
Naming pattern:
[app_name]/[model]_[function].html| Template purpose | Path |
| List all contacts | address_book/contact_list.html |
| Detail view of contact | address_book/contact_detail.html |
| Create/update form | address_book/contact_form.html |
| Confirm delete | address_book/contact_confirm_delete.html |
| Partial / inclusion tag | address_book/includes/contact_card.html |
Rules:
- Keep all templates in the project-level
templates/directory unless building a reusable app. - Partials rendered by inclusion tags go in
templates/[app]/includes/. - Non-HTML templates use the appropriate extension (
.txt,.xml,.json).
Template style (Django template language):
{# This is a comment — allowed before extends #}
{% extends "base.html" %}
{% load i18n static %}
{% block content %}
<h1>{{ page.title }}</h1>
{% for item in items %}
<p>{{ item.name }}</p>
{% endfor %}
{% if user.is_authenticated %}
<a href="{% url 'logout' %}">{% trans "Logout" %}</a>
{% endif %}
{% endblock content %}Template rules:
{% extends %}must be the first non-comment line.{% load %}libraries in alphabetical order:{% load i18n static %}not{% load static i18n %}.- Always name
{% endblock %}tags:{% endblock content %}not{% endblock %}. - Exactly one space inside
{{ variable }}and{% tag %}— never{{variable}}or{%tag%}. - No space around
.for attribute access or|for filters:{{ user.name|lower }}not{{ user.name | lower }}. - Never indent top-level
{% block %}tags inside{% extends %}templates.
Static Files & Media
# config/settings/base.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# --- Static files (CSS, JS, images — shipped with the project)
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles" # collectstatic target
STATICFILES_DIRS = [BASE_DIR / "static"] # source dirs
# --- Media files (user-generated uploads)
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media" # NEVER same dir as STATIC_ROOTRules:
- Always use
django.contrib.staticfiles— never hardcode/static/paths in templates. - In templates:
{% load static %}then{% static "css/main.css" %}. STATIC_ROOTandMEDIA_ROOTmust never be the same directory.- In development, add
urlpatterns += static(settings.MEDIA_URL, ...)to serve uploads locally. - In production, serve static via WhiteNoise or a CDN — never Django itself.
# config/urls.py — development media serving
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)django.conf.settings — Never Access at Module Import Time
Accessing django.conf.settings at module top-level breaks projects that configure
settings manually (e.g., in tests or CLI tools that call settings.configure()).
# WRONG — evaluated at import time; breaks manual settings.configure()
from django.conf import settings
from django.urls import get_callable
default_view = get_callable(settings.FOO_VIEW) # ❌ settings accessed at import# CORRECT — lazy wrapper evaluated only when called
from django.conf import settings
from django.utils.functional import lazy
def get_default_view():
"""Return the configured default view, resolved lazily."""
from django.urls import get_callable
return get_callable(settings.FOO_VIEW) # ✅ accessed at call timeRule: Any module-level code that reads from django.conf.settings must be wrapped
in a function, property, lazy(), or LazyObject. This is enforced by Django's own codebase.
Internationalisation (i18n)
All user-visible strings must be wrapped for translation:
# In Python code
from django.utils.translation import gettext_lazy as _
class UserProfile(models.Model):
class Meta:
verbose_name = _("user profile")
verbose_name_plural = _("user profiles")
# In views / services
from django.utils.translation import gettext as _
def activate_user(user: User) -> None:
if user.is_active:
raise ValidationError(_("User is already active."))Rules:
- Use
gettext_lazy(_) in model fields, Meta, forms, serializers — evaluated lazily. - Use
gettextin views and services — evaluated immediately (request context available). - Never use f-strings for strings that may need translation — format after wrapping:
# WRONG msg = f"Welcome, {user.name}!" # CORRECT msg = _("Welcome, %(name)s!") % {"name": user.name} - Run
makemessagesandcompilemessagesin CI.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

