更新
This commit is contained in:
@@ -62,8 +62,12 @@ DEBUG = config('DEBUG', default=True, cast=bool)
|
||||
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1', cast=lambda v: [s.strip() for s in v.split(',')])
|
||||
|
||||
# Database switch configuration
|
||||
# Database engine configuration (sqlite/mysql) with backward compatibility
|
||||
# Prefer `DB_ENGINE` env var; fallback to legacy `USE_REDIS_AS_DB`
|
||||
DB_ENGINE = config('DB_ENGINE', default=None)
|
||||
USE_REDIS_AS_DB = config('USE_REDIS_AS_DB', default=True, cast=bool)
|
||||
if DB_ENGINE is None:
|
||||
DB_ENGINE = 'sqlite' if USE_REDIS_AS_DB else 'mysql'
|
||||
|
||||
# Application definition
|
||||
|
||||
@@ -74,21 +78,27 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
|
||||
# Third party apps
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
'channels',
|
||||
'drf_spectacular',
|
||||
|
||||
|
||||
# 必备注册的app,不要删
|
||||
'hertz_demo', # 初始化演示模块
|
||||
'hertz_demo', # 初始化演示模块
|
||||
'hertz_studio_django_captcha', # 验证码模块
|
||||
'hertz_studio_django_auth', # 权限模块
|
||||
'hertz_studio_django_system_monitor', # 系统监测模块
|
||||
'hertz_studio_django_log', # 日志管理模块
|
||||
'hertz_studio_django_notice', # 通知模块
|
||||
|
||||
# ======在下面导入你需要的app======
|
||||
'hertz_studio_django_ai', #ai聊天模块
|
||||
'hertz_studio_django_kb', # 知识库 ai和kb库是相互绑定的
|
||||
'hertz_studio_django_wiki', # 文章模块
|
||||
'hertz_studio_django_yolo', # YOLO目标检测模块
|
||||
'hertz_studio_django_yolo_train', # Yolo训练模块
|
||||
|
||||
]
|
||||
|
||||
@@ -128,21 +138,17 @@ WSGI_APPLICATION = 'hertz_server_django.wsgi.application'
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||
|
||||
if USE_REDIS_AS_DB:
|
||||
# Redis as primary database (for caching and session storage)
|
||||
if DB_ENGINE == 'sqlite':
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'data/db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
# Use Redis for sessions
|
||||
# Use Redis-backed sessions when on SQLite (optional, keeps prior behavior)
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
||||
SESSION_CACHE_ALIAS = 'default'
|
||||
|
||||
else:
|
||||
# MySQL database configuration
|
||||
elif DB_ENGINE == 'mysql':
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
@@ -156,6 +162,14 @@ else:
|
||||
},
|
||||
}
|
||||
}
|
||||
else:
|
||||
# Fallback to SQLite for unexpected values
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'data/db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
# Redis
|
||||
CACHES = {
|
||||
|
||||
Reference in New Issue
Block a user