agentsclimarketplace

Django

Skill ComeOnOliver/skillshub/skills/TerminalSkills/skills/django

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.From the repository description

Install
npx -y skills add ComeOnOliver/skillshub --skill django

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

7.3 KB, ~1.7k tokens by cl100k_base, as published. Nobody here has run it

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_related and prefetch_related to avoid N+1 queries
  • Set AUTH_USER_MODEL early β€” 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-environ or os.environ for secrets β€” never hardcode
  • Run python manage.py check --deploy before production deployment

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.