update. 完成前端页面展示、列表和详情页
update. 调整融合主菜单与板块 update. 分离新闻模块
This commit is contained in:
+91
-14
@@ -11,10 +11,34 @@ https://docs.djangoproject.com/en/6.0/ref/settings/
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from loguru import logger
|
||||
import environ
|
||||
|
||||
env = environ.Env()
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# 获取 env文件路径
|
||||
env_file = BASE_DIR / "db/.env"
|
||||
|
||||
environ.Env.read_env(env_file)
|
||||
logger.info(".ENV变量输出", env.ENVIRON)
|
||||
# 日志文件存储配置
|
||||
LOGURU_FILE = {
|
||||
"is_show": "off",
|
||||
"level": "ERROR",
|
||||
'path': os.path.join(Path(__file__).parent, 'db/logs', 'test{time:YYYY-MM-DD}.logu'),
|
||||
"rotation": "10MB",
|
||||
'retention': "7days",
|
||||
}
|
||||
|
||||
# 日志控制台配置
|
||||
LOGURU_CONSOLE = {
|
||||
"is_show": "on", # 配置是否开启控制台打印日志
|
||||
"level": "INFO", # 最低打印级别是info级别
|
||||
}
|
||||
|
||||
# 日志文件夹不存在时创建
|
||||
logs_path = os.path.join(BASE_DIR, 'db/logs')
|
||||
if not os.path.exists(logs_path):
|
||||
@@ -29,7 +53,16 @@ SECRET_KEY = 'django-insecure-gr&k$v)_t*ax)yr1v9iz3x%$-j812ajpxs+fe2dn*dgy=a!730
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
ALLOWED_HOSTS = ['*', "127.0.0.1", "localhost"]
|
||||
|
||||
# 2. 【必须添加】这个配置专门用于解决 Origin checking failed 报错
|
||||
# 注意:必须包含协议头 (http://) 和端口号
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'http://127.0.0.1:11111', # 对应你报错的端口
|
||||
'http://127.0.0.1',
|
||||
'http://localhost:11111',
|
||||
'http://localhost',
|
||||
]
|
||||
|
||||
AUTH_USER_MODEL = 'users.User'
|
||||
|
||||
@@ -43,18 +76,21 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'import_export',
|
||||
'django_ckeditor_5',
|
||||
'base.apps.BaseConfig',
|
||||
'article.apps.ArticleConfig',
|
||||
'users.apps.UsersConfig',
|
||||
'front.apps.ContentConfig'
|
||||
'front.apps.ContentConfig',
|
||||
'news.apps.NewsConfig',
|
||||
'django_seed',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
# 'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
@@ -84,12 +120,40 @@ ASGI_APPLICATION = 'server.asgi.application'
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
if env('DB_REMOTE', default=False):
|
||||
# mysql_connect = dj_database_url.parse(os.getenv('MYSQL_CONNECTION'), conn_max_age=0)
|
||||
# print("数据库连接信息", mysql_connect)
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': env('DB_ENGINE', default='dj_db_conn_pool.backends.postgresql'),
|
||||
'NAME': env('DB_NAME', default='harvest'),
|
||||
'USER': env('DB_USER', default='harvest'),
|
||||
'PASSWORD': env('DB_PASSWORD', default='harvest'),
|
||||
'HOST': env('DB_HOST', default='harvest_postgres'),
|
||||
'PORT': env('DB_PORT', default=5432),
|
||||
'CONN_MAX_AGE': env('DB_CONN_MAX_AGE', default=0), # 必须设为 0,让池管理连接生命周期
|
||||
'OPTIONS': {
|
||||
# 'MAX_CONNS': env('DB_MAX_CONNS', default=30), # 池中最大物理连接数 (根据 PG 总限制调整)
|
||||
# 'REUSE_CONNS': env('DB_REUSE_CONNS', default=10), # 最小保留连接数
|
||||
},
|
||||
'POOL_OPTIONS': {
|
||||
'POOL_SIZE': env('DB_MAX_CONNS', default=100), # 增加连接池大小
|
||||
'MAX_OVERFLOW': 20, # 增加最大溢出连接数
|
||||
'TIMEOUT': 30, # 连接超时设置
|
||||
}
|
||||
},
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db/data.sqlite3',
|
||||
'OPTIONS': {
|
||||
'timeout': 120,
|
||||
'check_same_thread': False
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||
@@ -240,15 +304,25 @@ customColorPalette = [
|
||||
},
|
||||
]
|
||||
|
||||
CKEDITOR_5_CUSTOM_CSS = 'path_to.css' # optional
|
||||
CKEDITOR_5_FILE_STORAGE = "path_to_storage.CustomStorage" # optional
|
||||
# CKEDITOR_5_CUSTOM_CSS = 'path_to.css' # optional
|
||||
CKEDITOR_5_ALLOW_ALL_FILE_TYPES = True
|
||||
CKEDITOR_5_UPLOAD_FILE_TYPES = [
|
||||
'jpeg', 'png', 'jpg', 'gif', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx',
|
||||
]
|
||||
# 允许上传非图片文件(PDF、Word、Excel、ZIP等)
|
||||
CKEDITOR_ALLOW_NONIMAGE_FILES = True # 必须设为 True
|
||||
CKEDITOR_5_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' # optional
|
||||
CKEDITOR_5_CONFIGS = {
|
||||
'default': {
|
||||
'toolbar': {
|
||||
'items': ['heading', '|', 'bold', 'italic', 'link',
|
||||
'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],
|
||||
'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', 'uploadFile', ],
|
||||
},
|
||||
'language': 'zh-cn',
|
||||
# 2. 允许上传的文件类型 (根据需要扩展)
|
||||
'fileUploader': {
|
||||
'supportedFileTypes': ['pdf', 'doc', 'docx', 'zip', 'txt', 'jpg', 'png'],
|
||||
}
|
||||
|
||||
},
|
||||
'extends': {
|
||||
'blockToolbar': [
|
||||
@@ -261,12 +335,16 @@ CKEDITOR_5_CONFIGS = {
|
||||
'toolbar': {
|
||||
'items': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
|
||||
'code', 'subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',
|
||||
'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|',
|
||||
'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', 'uploadFile', '|',
|
||||
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
|
||||
'insertTable',
|
||||
],
|
||||
'shouldNotGroupWhenFull': 'true'
|
||||
},
|
||||
# --- 在 extends 配置中也必须加上这个 ---
|
||||
'fileUploader': {
|
||||
'supportedFileTypes': ['pdf', 'doc', 'docx', 'zip', 'txt']
|
||||
},
|
||||
'image': {
|
||||
'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
|
||||
'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],
|
||||
@@ -313,4 +391,3 @@ CKEDITOR_5_CONFIGS = {
|
||||
CKEDITOR_5_FILE_UPLOAD_PERMISSION = "staff" # Possible values: "staff", "authenticated", "any"
|
||||
|
||||
# CK_EDITOR_5_UPLOAD_FILE_VIEW_NAME = "custom_upload_file"
|
||||
|
||||
|
||||
+6
-3
@@ -17,7 +17,7 @@ Including another URLconf
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.urls import path, include
|
||||
from django.urls import path, include, re_path
|
||||
|
||||
import logging
|
||||
import os
|
||||
@@ -33,8 +33,9 @@ from ninja import NinjaAPI
|
||||
from ninja.errors import ValidationError
|
||||
from ninja.security import HttpBearer
|
||||
|
||||
from base.views import custom_upload_file
|
||||
from common.common_response import CommonResponse
|
||||
from .settings import SECRET_KEY
|
||||
from utils.common_response import CommonResponse
|
||||
|
||||
logger = logging.getLogger('ptools')
|
||||
|
||||
@@ -68,6 +69,7 @@ class GlobalAuth(HttpBearer):
|
||||
# 2. 获取当前文件所在的目录路径 (假设此文件与各个 app 文件夹同级,或者在特定配置目录下)
|
||||
# 如果你的此文件在项目根目录,而 app 文件夹也在根目录:
|
||||
from django.conf import settings
|
||||
|
||||
project_root = settings.BASE_DIR
|
||||
|
||||
|
||||
@@ -123,6 +125,7 @@ def auto_load_routers(base_path, package_name_prefix=None):
|
||||
except Exception as e:
|
||||
print(f"❌ 注册失败 {modname}: {e}")
|
||||
|
||||
|
||||
api_v1 = NinjaAPI(version='1.0.0', auth=GlobalAuth())
|
||||
auto_load_routers(project_root)
|
||||
|
||||
@@ -152,7 +155,7 @@ urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path("api/", api_v1.urls),
|
||||
path("ckeditor5/", include('django_ckeditor_5.urls')),
|
||||
# path("upload/", custom_upload_function, name="custom_upload_file"),
|
||||
path("upload/", custom_upload_file, name="custom_upload_file"),
|
||||
|
||||
]
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
|
||||
Reference in New Issue
Block a user