管理
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 设计与多媒体
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# Django Admin — Nudge
## Branding
The admin is branded to match Nudge's zinc-neutral + yellow-accent palette via a custom template:
`backend/templates/admin/base_site.html`
This template:
- Extends `admin/base.html` (NOT `admin/base_site.html` — that would loop)
- Overrides Django's CSS variables for both light and dark mode
- Sets the "Nudge" logo linking to `/` (the app, not `/admin/`)
- Forces white text on dark headers in all theme modes
- Repaints the "save" (default) submit button with the brand yellow (`#fcd34d`) so the primary CTA matches the app
### Color palette
Mirrors `frontend/src/index.css` — **source of truth lives there**. If it changes, update this template too.
| Token | Light | Dark |
|-----------------|------------|------------|
| Primary (text / bg dark) | `#18181b` | `#fafafa` |
| Primary hover | `#27272a` | `#e4e4e7` |
| Accent (brand) | `#fcd34d` | `#fcd34d` |
| Body bg | `#fafafa` | `#0a0a0b` |
| Surface | `#ffffff` | `#18181b` |
| Border | `#e4e4e7` | `#27272a` |
| Link | `#09090b` | `#fafafa` |
| Link hover | `#27272a` | `#fcd34d` |
### Django CSS variables to override
The key to theming Django admin is overriding its own CSS custom properties:
`--header-bg`, `--module-bg`, `--link-fg`, `--button-bg`, `--breadcrumbs-bg`, etc.
Do this for `:root`, `html[data-theme="light"]`, `html[data-theme="dark"]`,
and `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])`.
## Admin access from the PWA
The frontend has an "Admin" button (staff users only) in the Header component.
It works by creating a hidden form that POSTs the JWT token to `/api/auth/admin-access/`.
The backend view (`apps.users.views.admin_access`):
- Is `@csrf_exempt` (no CSRF token available from the SPA)
- Validates the JWT, checks `is_staff`
- Creates a Django session via `django_login()`
- Redirects to `/admin/`
## i18n
Django admin is multilingual out of the box. We enabled it by:
- Adding `django.middleware.locale.LocaleMiddleware` to `MIDDLEWARE`
(after `SessionMiddleware`, before `CommonMiddleware`)
- Setting `LANGUAGES = [("en", "English"), ("es", "Español"), ("gl", "Galego")]`
The admin auto-detects language from the browser's `Accept-Language` header.
## Registering models
Pattern used in `apps/users/admin.py`:
```python
@admin.register(User)
class UserAdmin(BaseUserAdmin):
fieldsets = BaseUserAdmin.fieldsets + (
("Nudge settings", {"fields": ("timezone", "daily_notification_time", "language")}),
)
list_display = ["username", "email", "timezone", "is_staff", "is_active"]
list_filter = ["is_staff", "is_active", "timezone"]
search_fields = ["username", "email"]
```
---
> Source: [cibrandocampo/nudge](https://github.com/cibrandocampo/nudge) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->
章节与文件索引
按说明文件中的顺序排列。
品牌推广
调色板
要覆盖的 Django CSS 变量
来自 PWA 的管理员访问权限
国际化
文件/命令 -> backend/templates/admin/base_site.html · admin/base.html · admin/base_site.html · (the app, not · #fcd34d · frontend/src/index.css · #18181b · #fafafa
内容校验值 -> b816874a291c
当前原文的自动摘译,尚未人工审校。
品牌推广
管理员的品牌是通过自定义模板匹配 Nudge 的锌中性 + 黄色调调色板:
backend/templates/admin/base_site.html此模板:扩展admin/base.html(不admin/base_site.html- 这会循环)覆盖 Django 的浅色和深色模式的 CSS 变量调色板
镜子
frontend/src/index.css——真理之源就在那里。如果发生变化,也更新此模板。令牌·浅色·深色主要(文本/背景深色)·#18181b·#fafafa主要悬停·#27272a·#e4e4e7口音(品牌)·#fcd34d·#fcd34d要覆盖的 Django CSS 变量
主题化 Django admin 的关键是覆盖它自己的 CSS 自定义属性:
--header-bg,--module-bg,--link-fg,--button-bg,--breadcrumbs-bg等。这样做是为了:root,html[data-theme="light"],html[data-theme="dark"], 和@media (prefers-color-scheme: dark)与:root:not([data-theme="light"])。来自 PWA 的管理员访问权限
前端的标题组件中有一个“管理”按钮(仅限员工用户)。它的工作原理是创建一个隐藏表单,将 JWT 令牌发布到
/api/auth/admin-access/。后端视图(apps.users.views.admin_access): 是@csrf_exempt(SPA 中没有可用的 CSRF 令牌)验证 JWT,检查is_staff国际化
Django admin 是开箱即用的多语言。我们通过以下方式启用它: 添加
django.middleware.locale.LocaleMiddleware到MIDDLEWARE(之后SessionMiddleware, 之前CommonMiddleware) 设置LANGUAGES = [("en", "English"), ("es", "Español"), ("gl", "Galego")]管理员会自动从浏览器中检测语言Accept-Language标头。