104 lines
3.0 KiB
Python
Executable File
104 lines
3.0 KiB
Python
Executable File
"""
|
||
Django settings for diary_system project.
|
||
"""
|
||
|
||
from pathlib import Path
|
||
import os
|
||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||
|
||
SECRET_KEY = 'django-insecure-diary-system-secret-key-change-in-production'
|
||
|
||
DEBUG = os.environ.get('DEBUG', 'True').lower() == 'true'
|
||
|
||
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(',')
|
||
|
||
INSTALLED_APPS = [
|
||
'django.contrib.admin',
|
||
'django.contrib.auth',
|
||
'django.contrib.contenttypes',
|
||
'django.contrib.sessions',
|
||
'django.contrib.messages',
|
||
'django.contrib.staticfiles',
|
||
'rest_framework',
|
||
'corsheaders',
|
||
'diary',
|
||
]
|
||
|
||
MIDDLEWARE = [
|
||
'django.middleware.security.SecurityMiddleware',
|
||
'corsheaders.middleware.CorsMiddleware',
|
||
'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',
|
||
]
|
||
|
||
ROOT_URLCONF = 'diary_system.urls'
|
||
|
||
TEMPLATES = [
|
||
{
|
||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||
'DIRS': [],
|
||
'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 = 'diary_system.wsgi.application'
|
||
|
||
# 数据库配置 - 云服务器使用 SQLite,本地使用 PostgreSQL
|
||
if os.path.exists('/home/ubuntu/diary-system'):
|
||
# 云服务器配置 - SQLite
|
||
DATABASES = {
|
||
'default': {
|
||
'ENGINE': 'django.db.backends.sqlite3',
|
||
'NAME': BASE_DIR / 'db.sqlite3',
|
||
}
|
||
}
|
||
else:
|
||
# 本地配置 - PostgreSQL
|
||
DATABASES = {
|
||
'default': {
|
||
'ENGINE': 'django.db.backends.postgresql',
|
||
'NAME': os.environ.get('DB_NAME', 'cssc'),
|
||
'USER': os.environ.get('DB_USER', 'coder'),
|
||
'PASSWORD': os.environ.get('DB_PASSWORD', '825670wl'),
|
||
'HOST': os.environ.get('DB_HOST', '10.2.0.100'),
|
||
'PORT': os.environ.get('DB_PORT', '5432'),
|
||
}
|
||
}
|
||
|
||
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 = 'zh-hans'
|
||
TIME_ZONE = 'UTC'
|
||
USE_I18N = True
|
||
USE_TZ = True
|
||
|
||
STATIC_URL = 'static/'
|
||
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||
|
||
CORS_ALLOW_ALL_ORIGINS = True
|
||
|
||
REST_FRAMEWORK = {
|
||
'DEFAULT_PERMISSION_CLASSES': [
|
||
'rest_framework.permissions.AllowAny',
|
||
]
|
||
}
|