diff --git a/.env b/.env new file mode 100644 index 0000000..2a83d1e --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +# Django settings +SECRET_KEY=django-insecure-&_@v3e5@!x+fa5273@v=^&02p@(#b89=p^06ifule17*p+g@u8 +DEBUG=True +ALLOWED_HOSTS=127.0.0.1,localhost + +# Static and media files +STATIC_ROOT=static +MEDIA_ROOT=media \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a6574a5 --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +# Django settings +SECRET_KEY=your-secret-key +DEBUG=True +ALLOWED_HOSTS=127.0.0.1,localhost + +# Database settings +# DATABASE_URL=sqlite:///db.sqlite3 +# For PostgreSQL: DATABASE_URL=postgres://user:password@localhost:5432/dbname +# For MySQL: DATABASE_URL=mysql://user:password@localhost:3306/dbname + +# Static and media files +STATIC_ROOT=static +MEDIA_ROOT=media \ No newline at end of file diff --git a/task_center/settings.py b/task_center/settings.py index 903e6bb..e255952 100644 --- a/task_center/settings.py +++ b/task_center/settings.py @@ -10,7 +10,12 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.0/ref/settings/ """ +import os from pathlib import Path +from dotenv import load_dotenv + +# 加载.env文件 +load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -19,13 +24,14 @@ BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ +# 基础配置 # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-&_@v3e5@!x+fa5273@v=^&02p@(#b89=p^06ifule17*p+g@u8' +SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-&_@v3e5@!x+fa5273@v=^&02p@(#b89=p^06ifule17*p+g@u8') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv('DEBUG', 'True') == 'True' -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') # Application definition @@ -105,9 +111,9 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/5.0/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'zh-hans' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Asia/Shanghai' USE_I18N = True @@ -117,7 +123,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.0/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = '/static/' +STATIC_ROOT = os.getenv('STATIC_ROOT', BASE_DIR / 'static') # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field @@ -133,7 +140,7 @@ REST_FRAMEWORK = { # Media files settings MEDIA_URL = '/media/' -MEDIA_ROOT = BASE_DIR / 'media' +MEDIA_ROOT = os.getenv('MEDIA_ROOT', BASE_DIR / 'media') # Test settings # TEST_RUNNER = 'pytest_django.runner.DjangoPytestTestRunner' # Commented out as it's not needed for pytest