Django定制admin主题

需求背景:由于测试服和生产服的样式相同,导致操作admin后台时,容易误操作;所以打算定制主题,让两者看起来明显不同。

之前就有用过django-admin-interface,感觉还不错,所以这次还是用它

pip install django-admin-interface

大致代码如下:

import os
import re
from pathlib import Path
from typing import List

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "..."

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = BASE_DIR.split("/")[2] != "prod-user-name"

ALLOWED_HOSTS: List[str] = ["xxx", "yyy"]


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    ...
]
if DEBUG:
    ALLOWED_HOSTS = ["*"]
    # https://pypi.org/project/django-admin-interface/
    INSTALLED_APPS[:0] = ["admin_interface", "colorfield"]
    X_FRAME_OPTIONS = "SAMEORIGIN"
    # python manage.py migrate
    # python manage.py loaddata admin_interface_theme_bootstrap.json
    # python manage.py collectstatic --clear  --no-input

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值