mirror of
https://github.com/hequan2017/seal.git
synced 2026-04-25 19:20:47 +08:00
245 lines
6.7 KiB
Python
245 lines
6.7 KiB
Python
"""
|
|
Django settings for seal project.
|
|
|
|
Generated by 'django-admin startproject' using Django 2.1.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/2.1/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/2.1/ref/settings/
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import socket
|
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = '#z!nrh$bn536iwb+#_9cp#lv3s(fdslwud(1()9he3qsnw@rzx'
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = True
|
|
|
|
ALLOWED_HOSTS = ['*']
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'system.apps.SystemConfig',
|
|
'assets.apps.AssetsConfig',
|
|
'bootstrap4',
|
|
'django_celery_results',
|
|
'django_celery_beat',
|
|
'rest_framework',
|
|
'rest_framework.authtoken',
|
|
'corsheaders',
|
|
'django_filters',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'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',
|
|
]
|
|
|
|
ROOT_URLCONF = 'seal.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [os.path.join(BASE_DIR, 'templates')]
|
|
,
|
|
'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 = 'seal.wsgi.application'
|
|
AUTH_USER_MODEL = 'system.users'
|
|
AUTHENTICATION_BACKENDS = ('system.views.CustomBackend',) ## 重新登录验证,增加邮箱名字也可以用作登录
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
|
|
|
|
|
if socket.gethostname().endswith('test'):
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'HOST': '192.168.100.50',
|
|
'PORT': '3306',
|
|
'NAME': 'seal',
|
|
'USER': 'root',
|
|
'PASSWORD': '123456',
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/2.1/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/2.1/topics/i18n/
|
|
|
|
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
|
|
SESSION_COOKIE_SAMESITE = 'Lax'
|
|
CSRF_COOKIE_SAMESITE = 'Lax'
|
|
SESSION_COOKIE_AGE = 432000
|
|
LOGIN_URL = '/auth/login'
|
|
LANGUAGE_CODE = 'zh-Hans'
|
|
|
|
TIME_ZONE = 'Asia/Shanghai'
|
|
|
|
USE_I18N = True
|
|
USE_L10N = False
|
|
USE_TZ = True
|
|
DATETIME_FORMAT = 'Y-m-d H:i:s'
|
|
DATE_FORMAT = 'Y-m-d'
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
|
STATICFILES_DIRS = (
|
|
os.path.join(BASE_DIR, 'static'),
|
|
)
|
|
|
|
# logging
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'formatters': {
|
|
'verbose': {
|
|
'format': '[argus] %(levelname)s %(asctime)s %(module)s %(message)s'
|
|
}
|
|
},
|
|
'handlers': {
|
|
'console': {
|
|
'level': 'DEBUG',
|
|
'class': 'logging.StreamHandler',
|
|
'stream': sys.stdout,
|
|
'formatter': 'verbose'
|
|
},
|
|
},
|
|
'loggers': {
|
|
'tasks': {
|
|
'handlers': ['console'],
|
|
'level': 'DEBUG',
|
|
'propagate': True,
|
|
},
|
|
'asset': {
|
|
'handlers': ['console'],
|
|
'level': 'DEBUG',
|
|
'propagate': True,
|
|
},
|
|
},
|
|
}
|
|
|
|
# 表格table
|
|
PAGINATION_SETTINGS = {
|
|
'PAGE_RANGE_DISPLAYED': 3,
|
|
'MARGIN_PAGES_DISPLAYED': 2,
|
|
'SHOW_FIRST_PAGE_WHEN_INVALID': True,
|
|
}
|
|
|
|
# 表格table 一页 展示数据
|
|
DISPLAY_PER_PAGE = 15
|
|
|
|
## celery 4
|
|
CELERY_RESULT_BACKEND = 'redis://localhost:6379/1'
|
|
# CELERY_RESULT_BACKEND = 'django-db'
|
|
CELERY_BROKER_URL = 'redis://localhost:6379/2'
|
|
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
|
|
CELERYD_CONCURRENCY = 4
|
|
CELERY_TIMEZONE = 'Asia/Shanghai'
|
|
CELERYD_MAX_TASKS_PER_CHILD = 10
|
|
CELERYD_FORCE_EXECV = True
|
|
|
|
# 设置默认不存结果
|
|
# CELERY_IGNORE_RESULT = True
|
|
CELERY_CREATE_MISSING_QUEUES = True
|
|
CELERY_DISABLE_RATE_LIMITS = True
|
|
CELERYD_TASK_SOFT_TIME_LIMIT = 600
|
|
|
|
CELERY_TASK_RESULT_EXPIRES = 600
|
|
CELERY_ENABLE_UTC = False
|
|
CELERY_TASK_SERIALIZER = 'json'
|
|
CELERY_RESULT_SERIALIZER = 'json'
|
|
|
|
## 钉钉 报警机器人 地址 调用地方为 system.tasks.ding_ding_to_info
|
|
web_hook_url = ""
|
|
|
|
## rest api
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
'rest_framework.authentication.BasicAuthentication',
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
),
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
'rest_framework.renderers.JSONRenderer',
|
|
'rest_framework.renderers.BrowsableAPIRenderer' #注释掉 可以关闭 api web界面
|
|
),
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
# 'rest_framework.permissions.AllowAny',
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
),
|
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
|
'PAGE_SIZE': 10,
|
|
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
|
|
}
|
|
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
CORS_ORIGIN_ALLOW_ALL = True
|
|
CORS_ORIGIN_WHITELIST = (
|
|
'*',
|
|
)
|
|
MIDDLEWARE_CLASSES = ('system.views.DisableCSRFCheck',)
|