278 lines
7.2 KiB
Python
278 lines
7.2 KiB
Python
![]() |
"""
|
||
|
Django settings for role_based_system project.
|
||
|
|
||
|
Generated by 'django-admin startproject' using Django 5.1.5.
|
||
|
|
||
|
For more information on this file, see
|
||
|
https://docs.djangoproject.com/en/5.1/topics/settings/
|
||
|
|
||
|
For the full list of settings and their values, see
|
||
|
https://docs.djangoproject.com/en/5.1/ref/settings/
|
||
|
"""
|
||
|
|
||
|
import os
|
||
|
from pathlib import Path
|
||
|
|
||
|
# API 配置
|
||
|
API_BASE_URL = 'http://81.69.223.133:48329'
|
||
|
|
||
|
DEPARTMENT_GROUPS = {
|
||
|
"技术部": ["开发组", "测试组", "运维组"],
|
||
|
"产品部": ["产品组", "设计组"],
|
||
|
"市场部": ["销售组", "推广组"],
|
||
|
"行政部": ["人事组", "财务组"]
|
||
|
}
|
||
|
|
||
|
# 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/5.1/howto/deployment/checklist/
|
||
|
|
||
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||
|
SECRET_KEY = 'django-insecure-5f*=0_2did)e(()n58=e#vd5gaf&y$thgt(h6&=p+wm1*r6mb='
|
||
|
|
||
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||
|
# 开发配置
|
||
|
# DEBUG = True
|
||
|
|
||
|
ALLOWED_HOSTS = ['*'] # 仅在开发环境使用
|
||
|
# 服务器配置
|
||
|
DEBUG = False
|
||
|
|
||
|
# ALLOWED_HOSTS = ['frptx.chiyong.fun', 'localhost', '127.0.0.1']
|
||
|
|
||
|
# Application definition
|
||
|
|
||
|
INSTALLED_APPS = [
|
||
|
'django.contrib.admin',
|
||
|
'django.contrib.auth',
|
||
|
'django.contrib.contenttypes',
|
||
|
'django.contrib.sessions',
|
||
|
'django.contrib.messages',
|
||
|
'django.contrib.staticfiles',
|
||
|
'rest_framework',
|
||
|
'rest_framework.authtoken',
|
||
|
'channels',
|
||
|
'user_management',
|
||
|
'channels_redis',
|
||
|
'corsheaders',
|
||
|
]
|
||
|
|
||
|
MIDDLEWARE = [
|
||
|
'corsheaders.middleware.CorsMiddleware', # CORS中间件要放在CommonMiddleware前面
|
||
|
'django.middleware.security.SecurityMiddleware',
|
||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||
|
'django.middleware.common.CommonMiddleware',
|
||
|
# 'django.middleware.csrf.CsrfViewMiddleware', # WebSocket不需要CSRF
|
||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||
|
'user_management.middleware.UserActivityMiddleware',
|
||
|
]
|
||
|
|
||
|
ROOT_URLCONF = 'role_based_system.urls'
|
||
|
|
||
|
TEMPLATES = [
|
||
|
{
|
||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||
|
'DIRS': [BASE_DIR / 'templates']
|
||
|
,
|
||
|
'APP_DIRS': True,
|
||
|
'OPTIONS': {
|
||
|
'context_processors': [
|
||
|
'django.template.context_processors.debug',
|
||
|
'django.template.context_processors.request',
|
||
|
'django.contrib.auth.context_processors.auth',
|
||
|
'django.contrib.messages.context_processors.messages',
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
]
|
||
|
|
||
|
WSGI_APPLICATION = 'role_based_system.wsgi.application'
|
||
|
|
||
|
|
||
|
# Database
|
||
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||
|
|
||
|
|
||
|
DATABASES = {
|
||
|
'default': {
|
||
|
'ENGINE': 'django.db.backends.mysql',
|
||
|
'NAME': 'rolebasedfilemanagement',
|
||
|
'USER': 'root',
|
||
|
'PASSWORD': '123456',
|
||
|
'HOST': 'localhost',
|
||
|
'PORT': '3306',
|
||
|
}
|
||
|
}
|
||
|
# Password validation
|
||
|
# https://docs.djangoproject.com/en/5.1/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',
|
||
|
},
|
||
|
]
|
||
|
|
||
|
|
||
|
|
||
|
LANGUAGE_CODE = 'en-us'
|
||
|
|
||
|
TIME_ZONE = 'UTC'
|
||
|
|
||
|
USE_I18N = True
|
||
|
|
||
|
USE_TZ = True
|
||
|
|
||
|
|
||
|
|
||
|
STATIC_URL = 'static/'
|
||
|
|
||
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||
|
|
||
|
AUTH_USER_MODEL = 'user_management.User'
|
||
|
|
||
|
REST_FRAMEWORK = {
|
||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||
|
'rest_framework.authentication.TokenAuthentication',
|
||
|
'rest_framework.authentication.SessionAuthentication',
|
||
|
],
|
||
|
'DEFAULT_PERMISSION_CLASSES': [
|
||
|
'rest_framework.permissions.IsAuthenticated',
|
||
|
]
|
||
|
}
|
||
|
|
||
|
# Channels 配置
|
||
|
ASGI_APPLICATION = "role_based_system.asgi.application"
|
||
|
|
||
|
# Channel Layers 配置
|
||
|
CHANNEL_LAYERS = {
|
||
|
"default": {
|
||
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||
|
"CONFIG": {
|
||
|
"hosts": [("127.0.0.1", 6379)],
|
||
|
"capacity": 1500, # 消息队列容量
|
||
|
"expiry": 10, # 消息过期时间(秒)
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
|
||
|
# CORS 配置
|
||
|
CORS_ALLOW_ALL_ORIGINS = True
|
||
|
CORS_ALLOW_CREDENTIALS = True
|
||
|
CORS_ALLOWED_ORIGINS = [
|
||
|
"http://localhost:8000",
|
||
|
"http://127.0.0.1:8000",
|
||
|
"ws://localhost:8000", # 添加 WebSocket
|
||
|
"ws://127.0.0.1:8000" # 添加 WebSocket
|
||
|
]
|
||
|
# 允许的请求头
|
||
|
CORS_ALLOWED_HEADERS = [
|
||
|
'accept',
|
||
|
'accept-encoding',
|
||
|
'authorization',
|
||
|
'content-type',
|
||
|
'dnt',
|
||
|
'origin',
|
||
|
'user-agent',
|
||
|
'x-csrftoken',
|
||
|
'x-requested-with',
|
||
|
]
|
||
|
|
||
|
# 允许的请求方法
|
||
|
CORS_ALLOWED_METHODS = [
|
||
|
'DELETE',
|
||
|
'GET',
|
||
|
'OPTIONS',
|
||
|
'PATCH',
|
||
|
'POST',
|
||
|
'PUT',
|
||
|
]
|
||
|
|
||
|
|
||
|
|
||
|
# WebSocket 允许的来源
|
||
|
CSRF_TRUSTED_ORIGINS = [
|
||
|
'http://localhost:8000',
|
||
|
'http://127.0.0.1:8000',
|
||
|
'ws://localhost:8000', # 添加 WebSocket
|
||
|
'ws://127.0.0.1:8000', # 添加 WebSocket
|
||
|
]
|
||
|
# 服务器配置
|
||
|
# 静态文件配置
|
||
|
STATIC_URL = '/static/'
|
||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||
|
|
||
|
# 媒体文件配置
|
||
|
MEDIA_URL = '/media/'
|
||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||
|
|
||
|
# 文件上传配置
|
||
|
FILE_UPLOAD_MAX_MEMORY_SIZE = 10 * 1024 * 1024 # 10MB
|
||
|
MAX_UPLOAD_SIZE = 10 * 1024 * 1024 # 10MB
|
||
|
|
||
|
# 日志配置
|
||
|
LOGGING = {
|
||
|
'version': 1,
|
||
|
'disable_existing_loggers': False,
|
||
|
'handlers': {
|
||
|
'console': {
|
||
|
'class': 'logging.StreamHandler',
|
||
|
},
|
||
|
'file': {
|
||
|
'class': 'logging.FileHandler',
|
||
|
'filename': 'debug.log',
|
||
|
},
|
||
|
},
|
||
|
'root': {
|
||
|
'handlers': ['console', 'file'],
|
||
|
'level': 'DEBUG',
|
||
|
},
|
||
|
}
|
||
|
|
||
|
# CSRF 配置
|
||
|
CSRF_COOKIE_SECURE = False # 开发环境设置为 False
|
||
|
CSRF_COOKIE_HTTPONLY = False
|
||
|
CSRF_USE_SESSIONS = False
|
||
|
CSRF_COOKIE_SAMESITE = 'Lax'
|
||
|
CSRF_TRUSTED_ORIGINS = [
|
||
|
'http://localhost:8000',
|
||
|
'http://127.0.0.1:8000',
|
||
|
'ws://localhost:8000', # 添加 WebSocket
|
||
|
'ws://127.0.0.1:8000' # 添加 WebSocket
|
||
|
]
|
||
|
|
||
|
# Session 配置
|
||
|
SESSION_COOKIE_SECURE = False # 开发环境设置为 False
|
||
|
SESSION_COOKIE_HTTPONLY = True
|
||
|
SESSION_COOKIE_SAMESITE = 'Lax'
|
||
|
|
||
|
# REST Framework 配置
|
||
|
REST_FRAMEWORK = {
|
||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||
|
'rest_framework.authentication.TokenAuthentication',
|
||
|
'rest_framework.authentication.SessionAuthentication', # WebSocket 需要
|
||
|
],
|
||
|
'DEFAULT_PERMISSION_CLASSES': [
|
||
|
'rest_framework.permissions.IsAuthenticated',
|
||
|
],
|
||
|
'DEFAULT_PARSER_CLASSES': [
|
||
|
'rest_framework.parsers.JSONParser',
|
||
|
'rest_framework.parsers.FormParser',
|
||
|
'rest_framework.parsers.MultiPartParser'
|
||
|
],
|
||
|
}
|