django-storages-s3
Skill này làm gì
Skill hướng dẫn agent AI thiết lập lưu trữ file cho Django trên AWS S3 bằng django-storages. Skill dành cho lập trình viên muốn file tải lên và tài nguyên tĩnh được giữ trên đám mây.
Khi nào nên dùng
- ✓Khi bạn muốn file tĩnh và file media của Django được phục vụ từ một bucket S3.
- ✓Khi bạn cần các file riêng tư được chia sẻ qua liên kết tải xuống đã ký trước.
- ✓Khi bạn muốn chuyển các file tải lên hiện có sang S3 mà không phải viết lại code.
Liên kết skill
https://github.com/Jeffallan/claude-skills/blob/main/skills/django-storages-s3/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chuyển file người dùng tải lên và file tĩnh Django của tôi sang một bucket S3, với các file riêng tư nằm sau liên kết có chữ ký.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent cài các gói, thiết lập thông tin xác thực và cấu hình STORAGES, rồi tách lưu trữ công khai khỏi riêng tư. Sau đó nó kiểm tra các file tải lên và thử nghiệm với lưu trữ giả.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Django Storages S3
Senior Django specialist for production-grade file storage on AWS S3 via django-storages and boto3 — public and private media, static files, presigned URLs, and CloudFront.
When to Use This Skill
- Serving static and/or media files from AWS S3 instead of the local filesystem
- Configuring the Django 4.2+
STORAGESdict or legacyDEFAULT_FILE_STORAGE - Separating public (CDN-served) and private (presigned) file backends
- Generating presigned download or direct browser-to-S3 upload URLs
- Fronting S3 with CloudFront and writing a least-privilege IAM policy
- Migrating local
FileField/ImageFieldstorage to S3 without code changes - Testing storage code without hitting S3
Core Workflow
- Install & register —
pip install django-storages[s3] boto3; add"storages"toINSTALLED_APPS - Configure credentials — Load from env vars or rely on an attached IAM role; never hardcode
- Wire the
STORAGESdict — Setdefault(media) andstaticfilesbackends with separatelocationprefixes - Add named backends — Split public vs. private buckets/ACLs as additional
STORAGESentries when needed - Verify & test — Run
collectstatic, confirm uploads land in S3, and mock S3 in tests withInMemoryStorageormoto
Reference Guide
Load detailed guidance based on context:
| Topic | Reference | Load When |
|---|---|---|
| Settings & STORAGES | references/configuration.md |
Core settings, 4.2+ vs legacy, CloudFront |
| Custom backends | references/custom-backends.md |
Public vs. private buckets, per-field storage |
| Presigned URLs | references/presigned-urls.md |
Download links, direct browser uploads |
| Testing & IAM | references/testing-storages.md |
Mocking S3, IAM policy, common pitfalls |
Minimal Working Example
The snippet below demonstrates the core MUST DO constraints: env-loaded credentials, STORAGES dict, separate media/static locations, and default_acl=None on the media backend.
# settings.py
import os
AWS_STORAGE_BUCKET_NAME = os.environ["AWS_STORAGE_BUCKET_NAME"]
AWS_S3_REGION_NAME = os.environ.get("AWS_S3_REGION_NAME", "us-east-1")
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com"
# On EC2/ECS/Lambda, omit keys entirely — boto3 uses the attached IAM role.
STORAGES = {
"default": { # media uploads
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
"OPTIONS": {
"bucket_name": AWS_STORAGE_BUCKET_NAME,
"location": "media",
"default_acl": None, # rely on bucket policy, not per-object ACLs
"file_overwrite": False,
"querystring_auth": False, # public objects → clean URLs
},
},
"staticfiles": {
"BACKEND": "storages.backends.s3boto3.S3StaticStorage",
"OPTIONS": {
"bucket_name": AWS_STORAGE_BUCKET_NAME,
"location": "static",
},
},
}
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/media/"
STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/static/"
# models.py — uploads go straight to S3 on save()
from django.db import models
class Document(models.Model):
file = models.FileField(upload_to="docs/") # uses STORAGES["default"]
Auditing an Existing Configuration
When reviewing a project that already uses S3 (not greenfield), walk this checklist — each item is a constraint below rephrased as "find X, confirm Y":
- Credentials —
grep -rn "AWS_SECRET_ACCESS_KEY\|aws_secret" settings/→ confirm values come fromos.environ/django-environor an IAM role, never literals committed to the repo. - ACLs —
grep -rn "default_acl\|AWS_DEFAULT_ACL" .→ on buckets created after April 2023, every value must beNone. Any"public-read"/"private"will raiseAccessControlListNotSupported; public access belongs in a bucket policy. - Storage backend — confirm Django 4.2+ uses the
STORAGESdict, notDEFAULT_FILE_STORAGE/STATICFILES_STORAGE(removed in Django 5.1, so silently ignored on 5.1/5.2/6.0); confirm the static class isS3StaticStorage, not a fabricated name. - Locations — confirm
default(media) andstaticfileshave distinctlocationprefixes or buckets socollectstaticnever collides with uploads. - Region — confirm
region_name(or the globalAWS_S3_REGION_NAME) matches the bucket's real region and thatAWS_S3_CUSTOM_DOMAINincludes the reg
Câu hỏi thường gặp
Nó có cần thông tin xác thực AWS không?
Có. Nó tải chúng từ biến môi trường hoặc IAM role gắn kèm, và không bao giờ viết cứng.
Nó có hỗ trợ CloudFront không?
Có. Nó bao quát việc đặt CloudFront trước S3.
Các test được xử lý thế nào?
Nó giả lập S3 trong test bằng lưu trữ trong bộ nhớ hoặc moto, nên test không kết nối tới S3 thật.
Chi tiết
Mô tả gốc của tác giả
Use when configuring Django to store static and media files on AWS S3 with django-storages. Invoke when working with the STORAGES setting, S3 buckets, presigned URLs, CloudFront, or boto3-backed file storage in settings.py. Configures the Django 4.2+ STORAGES dict, public/private custom backends, presigned GET/POST URLs, IAM policies, and S3 mocking for tests. Trigger terms: django-storages, S3, boto3, S3Boto3Storage, STORAGES, presigned URL, CloudFront, media files, collectstatic, AWS_STORAGE_BUCKET_NAME.
repo: Jeffallan/claude-skills
Độ phổ biến
- Sao GitHub
- 12k
- Vị trí xếp hạng
- #11419
- Giấy phép
- MIT
- Cập nhật
- 30/10/2026
Bình luận
- …
Thêm skill từ kho mã này
angular-architect
12kGiúp agent của bạn xây ứng dụng Angular 17 trở lên với standalone component, định tuyến lazy-loaded, state NgRx, mẫu RxJS và tinh chỉnh hiệu năng.
api-designer
12kGiúp agent của bạn thiết kế API REST hoặc GraphQL và viết đặc tả OpenAPI 3.1, với quy tắc cho tài nguyên, phân trang, định dạng lỗi và phiên bản.
architecture-designer
12kGiúp agent của bạn thiết kế kiến trúc hệ thống, so sánh các mẫu và công nghệ, và viết Architecture Decision Record giải thích từng lựa chọn.
atlassian-mcp
12kGiúp agent của bạn tìm kiếm và cập nhật issue Jira cùng trang Confluence qua MCP, gồm truy vấn JQL và CQL, sprint và đồng bộ tài liệu.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.