django
Djangoは、PythonでWebアプリケーションを効率的に開発するためのフレームワークで、データベース連携や認証機能などが標準装備されており、安全で機能豊富なWebサイトを迅速に構築するSkill。
📜 元の英語説明(参考)
Django is a batteries-included Python web framework that follows the model-template-view pattern. It provides an ORM, admin interface, authentication, and everything needed to build full-featured web applications rapidly and securely.
🇯🇵 日本人クリエイター向け解説
Djangoは、PythonでWebアプリケーションを効率的に開発するためのフレームワークで、データベース連携や認証機能などが標準装備されており、安全で機能豊富なWebサイトを迅速に構築するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o django.zip https://jpskill.com/download/14838.zip && unzip -o django.zip && rm django.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14838.zip -OutFile "$d\django.zip"; Expand-Archive "$d\django.zip" -DestinationPath $d -Force; ri "$d\django.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
django.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
djangoフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Django
Django は、迅速な開発を促進する高水準の Python ウェブフレームワークです。ORM、テンプレートエンジン、管理サイト、フォーム処理、認証、セキュリティミドルウェアが標準で含まれています。
インストール
# Django をインストールし、プロジェクトを開始します
pip install django
django-admin startproject myproject .
python manage.py startapp core
プロジェクト構造
# 標準的な Django プロジェクトのレイアウト
myproject/
├── manage.py
├── myproject/
│ ├── settings.py # 設定
│ ├── urls.py # ルート URL 設定
│ ├── wsgi.py # WSGI エントリーポイント
│ └── asgi.py # ASGI エントリーポイント
├── core/
│ ├── models.py # データベースモデル
│ ├── views.py # ビュー関数/クラス
│ ├── urls.py # アプリの URL パターン
│ ├── admin.py # 管理サイト登録
│ ├── forms.py # フォームクラス
│ ├── serializers.py # DRF シリアライザ
│ ├── templates/ # HTML テンプレート
│ └── tests.py
└── templates/ # プロジェクトレベルのテンプレート
モデル
# core/models.py — Django ORM を使用したデータベースモデル
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(blank=True)
avatar = models.ImageField(upload_to="avatars/", blank=True)
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
ビュー
# core/views.py — 関数ベースおよびクラスベースのビュー
from django.shortcuts import render, get_object_or_404, redirect
from django.views.generic import ListView, DetailView, CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Article
from .forms import ArticleForm
class ArticleListView(ListView):
model = Article
queryset = Article.objects.filter(published=True).select_related("author")
template_name = "core/article_list.html"
paginate_by = 20
class ArticleDetailView(DetailView):
model = Article
slug_field = "slug"
template_name = "core/article_detail.html"
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)
URL 設定
# core/urls.py — core アプリの URL パターン
from django.urls import path
from . import views
app_name = "core"
urlpatterns = [
path("", views.ArticleListView.as_view(), name="article-list"),
path("<slug:slug>/", views.ArticleDetailView.as_view(), name="article-detail"),
path("new/", views.ArticleCreateView.as_view(), name="article-create"),
]
# myproject/urls.py — ルート URL 設定
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("articles/", include("core.urls")),
path("api/", include("core.api_urls")),
]
管理サイト
# 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/core/article_list.html — リストビューテンプレート -->
{% extends "base.html" %}
{% block content %}
<h1>Articles</h1>
{% for article in object_list %}
<article>
<h2><a href="{{ article.get_absolute_url }}">{{ article.title }}</a></h2>
<p>By {{ article.author.username }} — {{ article.created_at|date:"M d, Y" }}</p>
</article>
{% empty %}
<p>No articles yet.</p>
{% endfor %}
{% include "core/_pagination.html" %}
{% endblock %}
Django REST Framework
# core/serializers.py — DRF シリアライザ
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", "title", "slug", "body", "author_name", "published", "created_at"]
read_only_fields = ["slug"]
# core/api_views.py — DRF ビューセット
from rest_framework import viewsets, permissions
from .models import Article
from .serializers import ArticleSerializer
class ArticleViewSet(viewsets.ModelViewSet):
queryset = Article.objects.filter(published=True)
serializer_class = ArticleSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
lookup_field = "slug"
def perform_create(self, serializer):
serializer.save(author=self.request.user)
マイグレーション
# データベースのマイグレーションを作成および適用します
python manage.py makemigrations core
python manage.py migrate
python manage.py createsuperuser
設定の要点
# myproject/settings.py — 設定する主要な設定
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "change-me")
DEBUG = os.environ.get("DEBUG", "True") == "True"
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "localhost").split(",")
AUTH_USER_MODEL = "core.User"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DB_NAME", "mydb"),
"USER": os.environ.get("DB_USER", "postgres" 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Django
Django is a high-level Python web framework that encourages rapid development. It includes an ORM, template engine, admin site, form handling, authentication, and security middleware out of the box.
Installation
# Install Django and start a project
pip install django
django-admin startproject myproject .
python manage.py startapp core
Project Structure
# Standard Django project layout
myproject/
├── manage.py
├── myproject/
│ ├── settings.py # Configuration
│ ├── urls.py # Root URL config
│ ├── wsgi.py # WSGI entry point
│ └── asgi.py # ASGI entry point
├── core/
│ ├── models.py # Database models
│ ├── views.py # View functions/classes
│ ├── urls.py # App URL patterns
│ ├── admin.py # Admin registration
│ ├── forms.py # Form classes
│ ├── serializers.py # DRF serializers
│ ├── templates/ # HTML templates
│ └── tests.py
└── templates/ # Project-level templates
Models
# core/models.py — database models with Django ORM
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(blank=True)
avatar = models.ImageField(upload_to="avatars/", blank=True)
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
Views
# core/views.py — function-based and class-based views
from django.shortcuts import render, get_object_or_404, redirect
from django.views.generic import ListView, DetailView, CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Article
from .forms import ArticleForm
class ArticleListView(ListView):
model = Article
queryset = Article.objects.filter(published=True).select_related("author")
template_name = "core/article_list.html"
paginate_by = 20
class ArticleDetailView(DetailView):
model = Article
slug_field = "slug"
template_name = "core/article_detail.html"
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)
URL Configuration
# core/urls.py — URL patterns for the core app
from django.urls import path
from . import views
app_name = "core"
urlpatterns = [
path("", views.ArticleListView.as_view(), name="article-list"),
path("<slug:slug>/", views.ArticleDetailView.as_view(), name="article-detail"),
path("new/", views.ArticleCreateView.as_view(), name="article-create"),
]
# myproject/urls.py — root URL configuration
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("articles/", include("core.urls")),
path("api/", include("core.api_urls")),
]
Admin
# core/admin.py — admin site registration
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
<!-- templates/core/article_list.html — list view template -->
{% extends "base.html" %}
{% block content %}
<h1>Articles</h1>
{% for article in object_list %}
<article>
<h2><a href="{{ article.get_absolute_url }}">{{ article.title }}</a></h2>
<p>By {{ article.author.username }} — {{ article.created_at|date:"M d, Y" }}</p>
</article>
{% empty %}
<p>No articles yet.</p>
{% endfor %}
{% include "core/_pagination.html" %}
{% endblock %}
Django REST Framework
# core/serializers.py — DRF serializers
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", "title", "slug", "body", "author_name", "published", "created_at"]
read_only_fields = ["slug"]
# core/api_views.py — DRF viewsets
from rest_framework import viewsets, permissions
from .models import Article
from .serializers import ArticleSerializer
class ArticleViewSet(viewsets.ModelViewSet):
queryset = Article.objects.filter(published=True)
serializer_class = ArticleSerializer
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
lookup_field = "slug"
def perform_create(self, serializer):
serializer.save(author=self.request.user)
Migrations
# Create and apply database migrations
python manage.py makemigrations core
python manage.py migrate
python manage.py createsuperuser
Settings Essentials
# myproject/settings.py — key settings to configure
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "change-me")
DEBUG = os.environ.get("DEBUG", "True") == "True"
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "localhost").split(",")
AUTH_USER_MODEL = "core.User"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DB_NAME", "mydb"),
"USER": os.environ.get("DB_USER", "postgres"),
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
"HOST": os.environ.get("DB_HOST", "localhost"),
}
}
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
Testing
# core/tests.py — Django test example
from django.test import TestCase, Client
from django.urls import reverse
from .models import Article, User
class ArticleTests(TestCase):
def setUp(self):
self.user = User.objects.create_user(username="test", password="pass1234")
self.article = Article.objects.create(
title="Test", slug="test", body="Hello", author=self.user, published=True
)
def test_list_view(self):
resp = self.client.get(reverse("core:article-list"))
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Test")
Running
# Run development server
python manage.py runserver 0.0.0.0:8000
Key Patterns
- Use
select_relatedandprefetch_relatedto avoid N+1 queries - Set
AUTH_USER_MODELearly — it's hard to change after first migration - Use class-based views for CRUD; function views for custom logic
- Middleware order matters: SecurityMiddleware first, then SessionMiddleware
- Use
django-environoros.environfor secrets — never hardcode - Run
python manage.py check --deploybefore production deployment