一键导入
django-knowledge-patch
Django
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Django
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
AlmaLinux
Angular
Arch Linux
Astro
Auth.js
AWS SDK
| name | django-knowledge-patch |
| description | Django |
| license | MIT |
| version | 6.0.8 |
| metadata | {"author":"Nevaberry"} |
Use this patch when implementing, reviewing, or upgrading Django applications and extensions. Start with the breaking-change checks, then load only the topic references needed for the task.
| Reference | Topics |
|---|---|
| upgrading.md | Runtime and database floors, removals, deprecations, compatibility boundaries, release status |
| orm-and-databases.md | Composite keys, expressions, queries, migrations, database options, backend extension APIs |
| http-security-auth.md | CSP, content negotiation, redirects, URL generation, authentication, sessions, passwords, DRF |
| tasks.md | Task declaration, backends, enqueueing, options, serialization, transactions, context, results |
| templates-forms-admin.md | Template partials and tags, form rendering, accessibility, admin behavior |
| email-and-feeds.md | Modern email objects, attachments, keyword-only calls, address settings, feed stylesheets |
| gis.md | Geometry APIs, spatial operations, GeoIP2, widgets, backend support |
| tooling-testing-serialization.md | Shell imports, commands, testing, pagination, serializers, scaffolding, static files |
Before changing application code or dependencies:
Pay particular attention to these changes:
STORAGES and storage aliases.Meta.index_together, legacy password hashers, removed PostgreSQL CI fields,
old prefetch extension hooks, joining-column fallbacks, and removed field-cache hooks.Field.pre_save() implementations idempotent.EmailMessage result and modern policy.ModelAdmin.lookup_allowed() overrides a request argument.format_html() and keyword arguments to BaseConstraint.Declare a virtual primary key whose component order defines tuple semantics:
class OrderLineItem(models.Model):
pk = models.CompositePrimaryKey("product_id", "order_id")
product = models.ForeignKey(Product, on_delete=models.CASCADE)
order = models.ForeignKey(Order, on_delete=models.CASCADE)
item = OrderLineItem.objects.get(pk=(1, "A755H"))
Account for the current limits:
_meta.pk_fields in reusable code; component fields do not set primary_key=True.pk to be absent from ModelForms.Count("pk") only where a database function explicitly supports composite expressions.pk assignment and filtering in component declaration order.Read orm-and-databases.md for validation, expression, introspection, raw-query, subquery, and migration details.
Declare tasks with @django.tasks.task, then enqueue them instead of calling them:
from django.tasks import task
@task(priority=2, queue_name="emails")
def email_users(user_ids):
...
result = email_users.enqueue([1, 2])
Treat the built-in backends as development and test facilities:
ImmediateBackend executes synchronously.DummyBackend records enqueue operations without executing them.Pass JSON-round-trippable values such as identifiers, not model instances, datetimes, or tuples.
When work depends on committed rows, enqueue it from transaction.on_commit().
Use aenqueue() in async code and read tasks.md before relying on
priorities, delayed execution, result lookup, or backend-specific capabilities.
Install ContentSecurityPolicyMiddleware and configure SECURE_CSP,
SECURE_CSP_REPORT_ONLY, or both. Use django.utils.csp.CSP constants so quoted source
expressions are correct.
from django.utils.csp import CSP
SECURE_CSP_REPORT_ONLY = {
"script-src": [CSP.SELF, CSP.NONCE, CSP.STRICT_DYNAMIC],
"report-uri": "/csp-reports/",
}
Remember:
nonce="{{ csp_nonce }}".Read http-security-auth.md for middleware placement, authentication, password, redirect, negotiation, and URL behavior.
Define reusable fragments directly in templates:
{% partialdef filter_controls inline %}
<form>{{ filter_form }}</form>
{% endpartialdef %}
{% partial filter_controls %}
Render only one fragment from a view by appending #<partial-name> to the template name.
Use simple_block_tag() for paired tags whose implementation only needs rendered block content.
Read templates-forms-admin.md for partial syntax,
custom BoundField selection, accessible error markup, form media, and admin changes.
request.get_preferred_type() with producible media types in server-preference order;
handle None when the Accept header allows none of them.query= and fragment= to reverse() or reverse_lazy() instead of assembling URLs.preserve_request=True to redirects that must retain the request method and body.query_params= with test clients and request factories for any HTTP method.URLField to assume HTTPS for schemeless input.values() and values_list() projection order to follow the call-site order.StringAgg delimiter in Value(); the delimiter is an expression.Aggregate.order_by only on aggregate classes that opt in with allow_order_by.AnyValue when grouping rules require an arbitrary non-null representative.GeneratedField values after save() according to backend
returning support; some backends defer the refresh until field access.Model.NotUpdated for a forced update that affects no rows.AsyncPaginator and AsyncPage in asynchronous code.Load orm-and-databases.md for backend-specific behavior and the extension contracts that affect custom expressions, fields, schema editors, and backends.
Prefer email.message.MIMEPart for inline and other structured attachments.
Expect EmailMessage.message() to return the standard-library message class under the modern
email policy. Treat attachments and alternatives as named tuples where Django exposes them,
and add alternatives only with attach_alternative().
Read email-and-feeds.md before maintaining custom mail classes,
legacy MIME attachment code, header-error handling, or ADMINS and MANAGERS settings.
method_decorator() wrap async view methods directly.test --pdb to stop at the calling test frame.TransactionTestCase.setUpClass().forkserver start method.Read tooling-testing-serialization.md for shell, management-command, testing, serializer, scaffolding, and static-file behavior.