Files
market_page/backend/config/settings.py
jeremygan2021 1100143a6e finish
2026-02-11 04:06:51 +08:00

304 lines
8.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Django settings for config project.
Generated by 'django-admin startproject' using Django 6.0.1.
For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-9hwh_v44(3n)61g)tiwkvm1k0h&5c+u=68&z*!$e0ujpd-6^1o'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
'unfold', # django-unfold必须在admin之前
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'drf_spectacular', # Swagger文档生成
'drf_spectacular_sidecar',
'shop',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ALLOW_ALL_ORIGINS = True
CSRF_TRUSTED_ORIGINS = [
"https://market.quant-speed.com",
"http://market.quant-speed.com",
]
ROOT_URLCONF = 'config.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'config.wsgi.application'
# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
# 优先使用 SQLite 进行本地开发,如果需要 PostgreSQL 请自行配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# 如果您坚持要使用 PostgreSQL请取消下面的注释并确保本地已启动 Postgres 服务
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': 'market',
# 'USER': 'market',
# 'PASSWORD': '123market',
# 'HOST': 'localhost',
# 'PORT': '5432',
# }
# }
# Password validation
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
# 静态文件配置
STATICFILES_DIRS = [
BASE_DIR / 'static',
]
# Django REST Framework配置
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
}
# drf-spectacular配置
SPECTACULAR_SETTINGS = {
'TITLE': '科技公司产品购买API',
'DESCRIPTION': '科技公司产品购买官网的API文档',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': True,
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
'COMPONENT_SPLIT_REQUEST': True,
'SWAGGER_UI_DIST': 'SIDECAR',
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
'REDOC_DIST': 'SIDECAR',
}
from django.urls import reverse_lazy
# django-unfold配置
UNFOLD = {
"SITE_TITLE": "量迹AI后台",
"SITE_HEADER": "量迹AI科技硬件/服务商场后台",
"SITE_URL": "/",
"COLORS": {
"primary": {
"50": "rgb(236 254 255)",
"100": "rgb(207 250 254)",
"200": "rgb(165 243 252)",
"300": "rgb(103 232 249)",
"400": "rgb(34 211 238)",
"500": "rgb(6 182 212)",
"600": "rgb(8 145 178)",
"700": "rgb(14 116 144)",
"800": "rgb(21 94 117)",
"900": "rgb(22 78 99)",
"950": "rgb(8 51 68)",
},
},
"SIDEBAR": {
"show_search": True,
"show_all_applications": False,
"navigation": [
{
"title": "用户管理",
"separator": True,
"items": [
{
"title": "微信用户",
"icon": "people",
"link": reverse_lazy("admin:shop_wechatuser_changelist"),
},
{
"title": "分销员管理",
"icon": "supervisor_account",
"link": reverse_lazy("admin:shop_salesperson_changelist"),
},
{
"title": "小程序分销员",
"icon": "groups",
"link": reverse_lazy("admin:shop_distributor_changelist"),
},
],
},
{
"title": "商品管理",
"separator": True,
"items": [
{
"title": "硬件配置 (小智参数)",
"icon": "hardware",
"link": reverse_lazy("admin:shop_esp32config_changelist"),
},
{
"title": "AI服务",
"icon": "smart_toy",
"link": reverse_lazy("admin:shop_service_changelist"),
},
{
"title": "VC课程",
"icon": "school",
"link": reverse_lazy("admin:shop_vccourse_changelist"),
},
],
},
{
"title": "交易管理",
"separator": True,
"items": [
{
"title": "订单列表",
"icon": "shopping_cart",
"link": reverse_lazy("admin:shop_order_changelist"),
},
{
"title": "服务订单",
"icon": "assignment",
"link": reverse_lazy("admin:shop_serviceorder_changelist"),
},
{
"title": "提现管理",
"icon": "account_balance_wallet",
"link": reverse_lazy("admin:shop_withdrawal_changelist"),
},
{
"title": "佣金记录",
"icon": "monetization_on",
"link": reverse_lazy("admin:shop_commissionlog_changelist"),
},
],
},
{
"title": "系统配置",
"separator": True,
"items": [
{
"title": "微信支付配置",
"icon": "payment",
"link": reverse_lazy("admin:shop_wechatpayconfig_changelist"),
},
{
"title": "用户认证",
"icon": "security",
"link": reverse_lazy("admin:auth_user_changelist"),
},
],
},
],
},
}
# 重新启用自动补齐斜杠,方便 Admin 使用
# 微信支付回调接口已在 urls.py 中配置 re_path 兼容无斜杠的情况
APPEND_SLASH = True
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
},
}