190 lines
5.2 KiB
Python
190 lines
5.2 KiB
Python
"""
|
||
Django settings for backend project.
|
||
|
||
Generated by 'django-admin startproject' using Django 5.2.1.
|
||
|
||
For more information on this file, see
|
||
https://docs.djangoproject.com/en/5.2/topics/settings/
|
||
|
||
For the full list of settings and their values, see
|
||
https://docs.djangoproject.com/en/5.2/ref/settings/
|
||
"""
|
||
import os
|
||
from pathlib import Path
|
||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||
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/
|
||
|
||
# SECURITY WARNING: keep the secret key used in production secret!
|
||
SECRET_KEY = 'django-insecure-m4@pv814c_m^pgpyhz^i96a@mcqh_@m9ccu(17*895t!79e!nb'
|
||
|
||
# SECURITY WARNING: don't run with debug turned on in production!
|
||
DEBUG = True
|
||
|
||
ALLOWED_HOSTS = [
|
||
'*',
|
||
]
|
||
INTERNAL_IPS = [
|
||
'*',
|
||
]
|
||
|
||
CORS_ORIGIN_ALLOW_ALL = True # 允许跨域名访问
|
||
CORS_ALLOW_CREDENTIALS = True
|
||
CORS_ALLOW_ALL_ORIGINS =True
|
||
|
||
# Application definition
|
||
|
||
INSTALLED_APPS = [
|
||
"simpleui",
|
||
'django.contrib.admin',
|
||
'django.contrib.auth',
|
||
'django.contrib.contenttypes',
|
||
'django.contrib.sessions',
|
||
'django.contrib.messages',
|
||
'django.contrib.staticfiles',
|
||
"rest_framework",
|
||
'django_filters',
|
||
'corsheaders',
|
||
'rest_framework.authtoken',
|
||
"system",
|
||
]
|
||
|
||
MIDDLEWARE = [
|
||
'django.middleware.security.SecurityMiddleware',
|
||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||
'corsheaders.middleware.CorsMiddleware',
|
||
'django.middleware.common.CommonMiddleware',
|
||
'django.middleware.csrf.CsrfViewMiddleware',
|
||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||
'django.contrib.messages.middleware.MessageMiddleware',
|
||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||
]
|
||
|
||
AUTH_USER_MODEL = 'system.User'
|
||
ROOT_URLCONF = 'backend.urls'
|
||
|
||
TEMPLATES = [
|
||
{
|
||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||
'DIRS': [],
|
||
'APP_DIRS': True,
|
||
'OPTIONS': {
|
||
'context_processors': [
|
||
'django.template.context_processors.request',
|
||
'django.contrib.auth.context_processors.auth',
|
||
'django.contrib.messages.context_processors.messages',
|
||
],
|
||
},
|
||
},
|
||
]
|
||
|
||
WSGI_APPLICATION = 'backend.wsgi.application'
|
||
|
||
|
||
# Database
|
||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||
|
||
DATABASES = {
|
||
'default': {
|
||
'ENGINE': 'django.db.backends.mysql',
|
||
'NAME': 'django_vue',
|
||
'USER': 'root',
|
||
'PASSWORD': '',
|
||
'HOST': os.getenv('DATABASE_HOST', 'localhost'),
|
||
# 'HOST': 'localhost',
|
||
}
|
||
}
|
||
|
||
# Password validation
|
||
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
||
|
||
AUTH_PASSWORD_VALIDATORS = [
|
||
{
|
||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||
},
|
||
{
|
||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||
},
|
||
{
|
||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||
},
|
||
{
|
||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||
},
|
||
]
|
||
|
||
|
||
# Internationalization
|
||
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
||
|
||
LANGUAGE_CODE = 'zh-hans'
|
||
|
||
# 设置为中国标准时间(CST,东八区)
|
||
TIME_ZONE = 'Asia/Shanghai'
|
||
|
||
# 启用国际化(多语言)
|
||
USE_I18N = True
|
||
|
||
# 启用本地化(格式化日期、数字等)
|
||
USE_L10N = True
|
||
|
||
# 是否使用时区支持(建议开启)
|
||
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, "static")
|
||
|
||
MEDIA_URL = '/media/'
|
||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') #自己在根目录下创建media文件夹
|
||
# Default primary key field type
|
||
# Default primary key field type
|
||
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||
|
||
REST_FRAMEWORK = {
|
||
'DEFAULT_PAGINATION_CLASS': 'utils.pagination.CustomPagination',
|
||
'PAGE_SIZE': 20,
|
||
'DEFAULT_FILTER_BACKENDS': (
|
||
'rest_framework.filters.OrderingFilter',
|
||
'django_filters.rest_framework.DjangoFilterBackend',
|
||
'rest_framework.filters.SearchFilter',
|
||
),
|
||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||
'utils.authentication.BearerTokenAuthentication',
|
||
'rest_framework.authentication.BasicAuthentication',
|
||
'rest_framework.authentication.SessionAuthentication',
|
||
'rest_framework.authentication.TokenAuthentication',
|
||
],
|
||
'DEFAULT_PERMISSION_CLASSES': [
|
||
'rest_framework.permissions.AllowAny',
|
||
]
|
||
}
|
||
|
||
# celery 配置
|
||
CELERY_BROKER_URL = 'redis://localhost:6379/6'
|
||
CELERY_RESULT_BACKEND = 'redis://localhost:6379/6'
|
||
# 时区设置
|
||
CELERY_TIMEZONE = 'Asia/Shanghai'
|
||
# 任务序列化方式
|
||
CELERY_TASK_SERIALIZER = 'json'
|
||
CELERY_RESULT_SERIALIZER = 'json'
|
||
CELERY_ACCEPT_CONTENT = ['json']
|
||
|
||
CELERY_BEAT_SCHEDULE = {
|
||
'every-1-minutes': {
|
||
'task': 'system.tasks.sync_temu_order', # 任务路径
|
||
'schedule': 60, # 每1分钟执行一次
|
||
},
|
||
}
|
||
# celery 配置结束
|
||
|
||
if os.path.exists(os.path.join(BASE_DIR, 'backend/local_settings.py')):
|
||
from backend.local_settings import * |