You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
7.1 KiB
Python
246 lines
7.1 KiB
Python
"""
|
|
Django settings for XZNSH_API project.
|
|
|
|
Generated by 'django-admin startproject' using Django 3.2.19.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/3.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/3.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
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = 'django-insecure-kqm6r(-!q-emw5c!!@dc)9l^hm@m#4!)-d7ecq85&u^5leu5)_'
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = False
|
|
|
|
ALLOWED_HOSTS = ["*"]
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'rest_framework',
|
|
'django_filters',
|
|
'corsheaders',
|
|
'app',
|
|
'event',
|
|
'user',
|
|
]
|
|
|
|
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',
|
|
'mymiddleware.middleware.CheckTokenMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'XZNSH_API.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'XZNSH_API.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
|
|
|
# DATABASES = {
|
|
# 'default': {
|
|
# 'ENGINE': 'django.db.backends.sqlite3',
|
|
# 'NAME': BASE_DIR / 'db.sqlite3',
|
|
# }
|
|
# }
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'NAME': 'xznsh_test',
|
|
'USER': 'root',
|
|
'PASSWORD': '123abc',
|
|
'HOST': '127.0.0.1',
|
|
'PORT': '3306',
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/3.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/3.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'zh-hans'
|
|
|
|
TIME_ZONE = 'Asia/Shanghai'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = False
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
# 解决跨域
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
CORS_ORIGIN_ALLOW_ALL = True
|
|
CORS_ALLOW_HEADERS = ["*"]
|
|
|
|
# CORS_ORIGIN_WHITELIST = ('*',)
|
|
# 对应的发送的请求的跨域
|
|
CORS_ALLOW_METHODS = (
|
|
'DELETE',
|
|
'GET',
|
|
'OPTIONS',
|
|
'PATCH',
|
|
'POST',
|
|
'PUT',
|
|
'VIEW',
|
|
)
|
|
|
|
USE_L10N = False
|
|
DATE_FORMAT = 'Y-m-d'
|
|
DATETIME_FORMAT = 'Y-m-d H:M:S'
|
|
|
|
REST_FRAMEWORK = {
|
|
'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
|
|
'DATE_FORMAT': "%Y-%m-%d",
|
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
|
|
'EXCEPTION_HANDLER': 'app.exception.exception_handler',
|
|
# 'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
# 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', # 第一种jwt方式
|
|
# # 'rest_framework.authentication.SessionAuthentication', # 第二种session方式
|
|
# # 'rest_framework.authentication.BasicAuthentication', # 第三种Django的基本方式
|
|
# ),
|
|
#
|
|
# 'DEFAULT_PERMISSION_CLASSES': (
|
|
# 'rest_framework.permissions.IsAuthenticated',
|
|
# ),
|
|
}
|
|
|
|
# 配置日志
|
|
LOG_DIR = os.path.join(BASE_DIR, 'logs')
|
|
LOGGING = {
|
|
'version': 1, # 保留字
|
|
'disable_existing_loggers': False, # 是否禁用已经存在的日志实例
|
|
'formatters': { # 定义日志的格式
|
|
'standard': {
|
|
'format': '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'
|
|
'[%(levelname)s]%(message)s'
|
|
},
|
|
'simple': {
|
|
'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
|
|
},
|
|
'collect': {
|
|
'format': '%(message)s'
|
|
}
|
|
},
|
|
'filters': { # 定义日志的过滤器
|
|
'require_debug_true': {
|
|
'()': 'django.utils.log.RequireDebugTrue',
|
|
},
|
|
},
|
|
'handlers': { # 日志处理程序
|
|
'console': {
|
|
'level': 'DEBUG',
|
|
'filters': ['require_debug_true'], # 只有在Django debug为True时才在屏幕打印日志
|
|
'class': 'logging.StreamHandler',
|
|
'formatter': 'simple',
|
|
# 'filename': os.path.join(BASE_LOG_DIR, "tpservice.log")
|
|
},
|
|
# 'file': {
|
|
# 'level': 'INFO',
|
|
# 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler', # window多进程 需要 pip install concurrent-log-handler
|
|
# 'filename': os.path.join(BASE_DIR, "logs/debug.log"), # 日志文件
|
|
# 'backupCount': 10, # 保留的最大文件数,超过则删除日期最早的
|
|
# 'maxBytes': 1024 * 1024 * 10, # 文件大小
|
|
# 'formatter': 'standard',
|
|
# 'encoding': 'utf-8',
|
|
# },
|
|
# 'file': {
|
|
# 'level': 'INFO',
|
|
# 'class': 'cloghandler.ConcurrentRotatingFileHandler', # linux多进程 需要 pip install ConcurrentLogHandler
|
|
# 'filename': os.path.join(BASE_DIR, "logs/debug.log"), # 日志文件
|
|
# 'backupCount': 10, # 保留的最大文件数,超过则删除日期最早的
|
|
# 'maxBytes': 1024 * 1024 * 10, # 文件大小
|
|
# 'formatter': 'standard',
|
|
# 'encoding': 'utf-8',
|
|
# },
|
|
},
|
|
'loggers': { # 日志实例 记录器
|
|
'mylogger': { # 默认的logger应用如下配置
|
|
'handlers': ['console'],
|
|
'level': 'DEBUG',
|
|
'propagate': True, # 是否向上一级logger实例传递日志信息
|
|
},
|
|
},
|
|
}
|
|
|
|
AUTH_USER_MODEL = 'user.UserProfile'
|