Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

django

FreeNo executable scriptsNot checked

Django is a batteries-included Python web framework with an ORM, admin site, authentication, forms and templates. Use when asked to start a Django project…

TerminalSkillsby TerminalSkills★ 221 GitHub stars

About this skill

Django

Overview

Django is a high-level Python web framework with an ORM, migrations, admin site, forms, template engine, authentication and security middleware built in. Current release is Django 6.1 (needs Python 3.12 or newer); the 5.2 LTS series is the last that supports Python 3.10 and 3.11, and 6.2 is the next LTS. Django 6.0 added built-in Content Security Policy support and a Tasks framework (django.tasks). The code below was run on Django 6.1.2 with Django REST framework 3.18.3 and Pillow 13: manage.py check is clean and the tests pass.

Instructions

Install and start a project

$ python3 -m venv .venv && source .venv/bin/activate
$ pip install django djangorestframework pillow
$ django-admin startproject newsroom .
$ python manage.py startapp core

Pillow is only needed for ImageField. Add 'rest_framework' and 'core' to INSTALLED_APPS, and set AUTH_USER_MODEL = "core.User" before the first migration: changing it later is painful.

Models

# core/models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse


class User(AbstractUser):
    bio = models.TextField(blank=True)
    avatar = models.ImageField(upload_to="avatars/", blank=True)  # needs Pillow


class Article(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True)
    body = models.TextField()
    author = models.ForeignKey(User, on_delete=models.CASCADE, related_name="articles")
    published = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ["-created_at"]

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("core:article-detail", kwargs={"slug": self.slug})

Views

The detail view filters to published articles, so drafts return 404. DetailView finds the object by the slug URL kwarg by default.

# core/views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import CreateView, DetailView, ListView

from .forms import ArticleForm
from .models import Article


class ArticleListView(ListView):
    queryset = Article.objects.filter(published=True).select_related("author")
    template_name = "core/article_list.html"
    paginate_by = 20


class ArticleDetailView(DetailView):
    queryset = Article.objects.filter(published=True).select_related("author")
    template_name = "core/article_detail.html"  # looks up by the <slug:slug> URL kwarg


class ArticleCreateView(LoginRequiredMixin, CreateView):
    model = Article
    form_class = ArticleForm
    template_name = "core/article_form.html"

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)

URLs

Order matters: new/ must come before <slug:slug>/, otherwise "new" is read as a slug and the create view is unreachable.

# core/urls.py
from django.urls import path

from . import views

app_name = "core"
urlpatterns = [
    path("", views.ArticleListView.as_view(), name="article-list"),
    path("new/", views.ArticleCreateView.as_view(), name="article-create"),  # before the slug route
    path("<slug:slug>/", views.ArticleDetailView.as_view(), name="article-detail"),
]
# newsroom/urls.py
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("admin/", admin.site.urls),
    path("articles/", include("core.urls")),
    path("api/", include("core.api_urls")),
]

Forms and admin

ArticleForm is a ModelForm with fields = ["title", "slug", "body", "published"] (never __all__, so author stays server-controlled).

# core/admin.py
from django.contrib import admin

from .models import Article


@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    list_display = ["title", "author", "published", "created_at"]
    list_filter = ["published", "created_at"]
    search_fields = ["title", "body"]
    prepopulated_fields = {"slug": ("title",)}
    raw_id_fields = ["author"]

Templates

Add BASE_DIR / "templates" to TEMPLATES["DIRS"] and create templates/base.html with a {% block content %}. The list template (core/templates/core/article_list.html) loops {% for article in object_list %} with {% empty %}, links with {{ article.get_absolute_url }}, and shows pagination from is_paginated, page_obj.has_previous and page_obj.has_next (the ?page=N links).

REST API with Django REST framework

# core/serializers.py
from rest_framework import serializers

from .models import Article


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

    class Meta:
        model = Article
        fields = ["id", "titl
Full SKILL.md on GitHub

Install django in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

_scores.json

FAQ

What does the django skill do?

Django is a batteries-included Python web framework with an ORM, admin site, authentication, forms and templates. Use when asked to start a Django project, write models, views, URLs or admin, add a REST API with Django REST framework, run migrations, configure settings for production, or write Django tests.

How do I install the django skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the django skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare django with