fix: 添加 STATIC_ROOT 和 MEDIA_ROOT 配置

- 支持从环境变量配置静态文件和媒体文件路径
- 默认使用项目目录下的 static 和 media 文件夹
This commit is contained in:
maoshen
2026-04-12 22:06:40 +00:00
parent 89e8589e87
commit e343de64b5

View File

@@ -144,12 +144,18 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.2/howto/static-files/ # https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'static/'
STATIC_ROOT = os.environ.get('STATIC_ROOT', BASE_DIR / 'static')
STATICFILES_DIRS = []
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Media files
MEDIA_URL = 'media/'
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', BASE_DIR / 'media')
# 自定义用户模型 # 自定义用户模型
AUTH_USER_MODEL = 'users.User' AUTH_USER_MODEL = 'users.User'