feat: add apps and custom user
This commit is contained in:
+39
-4
@@ -20,6 +20,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||
|
||||
def load_dotenv(path: Path) -> None:
|
||||
if not path.exists():
|
||||
return
|
||||
for raw_line in path.read_text(encoding="utf-8-sig").splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, value = line.split("=", 1)
|
||||
os.environ.setdefault(key.strip(), value.strip().strip('"').strip("'"))
|
||||
|
||||
|
||||
def env_bool(name: str, default: bool = False) -> bool:
|
||||
value = os.environ.get(name)
|
||||
if value is None:
|
||||
@@ -32,6 +43,15 @@ def env_list(name: str, default: str = "") -> list[str]:
|
||||
return [item.strip() for item in value.split(",") if item.strip()]
|
||||
|
||||
|
||||
def env_int(name: str, default: int) -> int:
|
||||
value = os.environ.get(name)
|
||||
if not value:
|
||||
return default
|
||||
return int(value)
|
||||
|
||||
|
||||
load_dotenv(BASE_DIR / ".env")
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret.
|
||||
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "django-insecure-dev-only-change-me")
|
||||
|
||||
@@ -45,6 +65,11 @@ ALLOWED_HOSTS = env_list("DJANGO_ALLOWED_HOSTS", "127.0.0.1,localhost")
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'rest_framework',
|
||||
'apps.users',
|
||||
'apps.portal',
|
||||
'apps.billing',
|
||||
'apps.ai',
|
||||
'apps.api',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@@ -82,14 +107,24 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
AUTH_USER_MODEL = 'users.User'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'HOST': os.environ.get('MYSQL_HOST', '127.0.0.1'),
|
||||
'PORT': env_int('MYSQL_PORT', 3306),
|
||||
'NAME': os.environ.get('MYSQL_DATABASE', 'cmhub'),
|
||||
'USER': os.environ.get('MYSQL_USER', ''),
|
||||
'PASSWORD': os.environ.get('MYSQL_PASSWORD', ''),
|
||||
'OPTIONS': {
|
||||
'charset': os.environ.get('MYSQL_CHARSET', 'utf8mb4'),
|
||||
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,9 +151,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = 'zh-hans'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = os.environ.get('DJANGO_TIME_ZONE', 'Asia/Shanghai')
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user