From a32818b55eb42f7c1585c3dea275d6397784ca236b14a088d10611c479db38e1 Mon Sep 17 00:00:00 2001 From: yuangyaa Date: Thu, 30 Jul 2026 09:42:08 +0800 Subject: [PATCH] change filedir for data --- myblog/myblog/settings.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/myblog/myblog/settings.py b/myblog/myblog/settings.py index 77907f3..9352515 100644 --- a/myblog/myblog/settings.py +++ b/myblog/myblog/settings.py @@ -11,10 +11,10 @@ https://docs.djangoproject.com/en/5.2/ref/settings/ """ from pathlib import Path -import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +DATA_DIR = BASE_DIR.parent / 'data' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ @@ -110,13 +110,11 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.2/howto/static-files/ -STATIC_URL = 'static/' -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') - -# 添加媒体文件配置 +STATIC_URL = '/static/' +STATIC_ROOT = DATA_DIR / 'static' MEDIA_URL = '/media/' -MEDIA_ROOT = os.path.join(BASE_DIR, 'media') +MEDIA_ROOT = DATA_DIR / 'media' # Default primary key field type # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field @@ -159,6 +157,31 @@ MDEDITOR_CONFIGS = { X_FRAME_OPTIONS = 'SAMEORIGIN' +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': '{levelname} {asctime} {module} {message}', + 'style': '{', + }, + }, + 'handlers': { + 'file': { + 'level': 'WARNING', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': DATA_DIR / 'logs' / 'django.log', + 'maxBytes': 1024 * 1024 * 5, + 'backupCount': 5, + 'formatter': 'verbose', + }, + }, + 'root': { + 'handlers': ['file'], + 'level': 'WARNING', + }, +} + # settings.py 末尾加上这段 try: from .local_settings import *