123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- import os
- from AnsjerPush.config import BASE_DIR
- from dotenv import load_dotenv
- load_dotenv(os.path.join(BASE_DIR, '.env'))
- def get_list(name, default=None, sep=","):
- value = os.getenv(name)
- if value is None:
- return default or []
- return [x.strip() for x in value.split(sep) if x.strip()]
- ACCESS_KEY_ID = os.getenv('ACCESS_KEY_ID', default='')
- SECRET_ACCESS_KEY = os.getenv('SECRET_ACCESS_KEY', default='')
- AWS_ACCESS_KEY_ID = get_list('AWS_ACCESS_KEY_ID', default=[])
- AWS_SECRET_ACCESS_KEY = get_list('AWS_SECRET_ACCESS_KEY', default=[])
- ALICLOUD_AK = os.getenv('ALICLOUD_AK', default='')
- ALICLOUD_SK = os.getenv('ALICLOUD_SK', default='')
- OSS_ROLE_ARN = os.getenv('OSS_ROLE_ARN', default='')
- HUAWEICLOUD_AK = os.getenv('HUAWEICLOUD_AK', default='')
- HUAWEICLOUD_SK = os.getenv('HUAWEICLOUD_SK', default='')
- SECRET_KEY = '$2hf5g$a%_^kk0-l25l$!o5)yc=dvtnfpc8(+$rh4fq4twa_xx'
- DEBUG = False
- ALLOWED_HOSTS = ["*"]
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'corsheaders',
- 'imagekit',
- 'Model'
- ]
- MIDDLEWARE = [
- 'django.middleware.security.SecurityMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'corsheaders.middleware.CorsMiddleware',
- 'django.middleware.common.CommonMiddleware',
- # 'MiddleWare.requestRecord.RequestRecordMiddleware', # 记录请求信息
- # 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
- ]
- ROOT_URLCONF = 'AnsjerPush.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 = 'AnsjerPush.wsgi.application'
- # 业务数据库
- DATABASE_DATA = os.getenv('DATABASE_DATA')
- SERVER_HOST = os.getenv('SERVER_HOST')
- DATABASES_USER = os.getenv('DATABASES_USER')
- DATABASES_PASS = os.getenv('DATABASES_PASS')
- # 推送数据库
- DATABASE_DATA2 = os.getenv('DATABASE_DATA2')
- SERVER_HOST2 = os.getenv('SERVER_HOST2')
- DATABASES_USER2 = os.getenv('DATABASES_USER2')
- DATABASES_PASS2 = os.getenv('DATABASES_PASS2')
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': DATABASE_DATA,
- 'USER': DATABASES_USER,
- 'PASSWORD': DATABASES_PASS,
- 'HOST': SERVER_HOST,
- 'PORT': '3306',
- 'AUTOCOMMIT': True,
- 'OPTIONS': {'charset': 'utf8mb4',
- 'use_unicode': True,
- 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
- }
- },
- 'mysql02': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': DATABASE_DATA2,
- 'USER': DATABASES_USER2,
- 'PASSWORD': DATABASES_PASS2,
- 'HOST': SERVER_HOST2,
- 'PORT': '3306',
- 'AUTOCOMMIT': True,
- 'OPTIONS': {'charset': 'utf8mb4',
- 'use_unicode': True,
- 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
- }
- }
- }
- DATABASE_ROUTERS = ['AnsjerPush.database_router.DatabaseAppsRouter']
- DATABASE_APPS_MAPPING = {
- 'db1': 'default',
- 'db2': 'mysql02',
- }
- # 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/
- LANGUAGE_CODE = 'en-us'
- TIME_ZONE = 'UTC'
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- # Static files (CSS, JavaScript, Images)
- # https://docs.djangoproject.com/en/2.1/howto/static-files/
- STATIC_URL = '/static/'
- # 跨域增加忽略
- # 跨域增加忽略
- CORS_ALLOW_CREDENTIALS = True
- CORS_ORIGIN_ALLOW_ALL = True
- CORS_ORIGIN_WHITELIST = ()
- CORS_ALLOW_METHODS = (
- 'DELETE',
- 'GET',
- 'OPTIONS',
- 'PATCH',
- 'POST',
- 'PUT',
- 'VIEW',
- )
- CORS_ALLOW_HEADERS = (
- 'accept',
- 'accept-encoding',
- 'authorization',
- 'content-type',
- 'dnt',
- 'origin',
- 'user-agent',
- 'x-csrftoken',
- 'x-requested-with',
- )
- # 日志模块
- LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': True,
- 'formatters': {
- 'error_format': {
- 'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
- },
- 'standard': {
- 'format': '[%(asctime)s] [%(filename)s:%(lineno)d] [%(module)s:%(funcName)s] '
- '[%(levelname)s]- %(message)s'},
- },
- 'filters': {
- },
- 'handlers': {
- 'mail_admins': {
- 'level': 'ERROR',
- 'class': 'django.utils.log.AdminEmailHandler',
- 'include_html': True,
- },
- 'default': {
- 'level': 'ERROR',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/error/error.log',
- 'maxBytes': 1024 * 1024 * 5, # 5 MB
- 'backupCount': 3,
- 'formatter': 'error_format',
- },
- 'console': {
- 'level': 'ERROR',
- 'class': 'logging.StreamHandler',
- 'formatter': 'error_format'
- },
- # 总计info、time、v1_push日志给57GB空间
- 'info': {
- 'level': 'INFO',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/info/info.log',
- 'backupCount': 3,
- 'maxBytes': 1024 * 1024 * 2 * 1024, # 一天以内2GB 保存5天共10GB
- 'formatter': 'standard',
- 'encoding': 'utf-8',
- },
- 'time': {
- 'level': 'INFO',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/time/info.log',
- 'backupCount': 7,
- 'maxBytes': 1024 * 1024 * 5 * 1024, # 一天9GB 保存5天 共45GB
- 'formatter': 'standard',
- 'encoding': 'utf-8',
- },
- 'v1_push': {
- 'level': 'INFO',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/v1log/info.log',
- 'backupCount': 1,
- 'maxBytes': 1024 * 1024 * 1 * 1024, # 一天0.05GB 保存40天 共2GB
- 'formatter': 'standard',
- 'encoding': 'utf-8',
- },
- 'customized_push': {
- 'level': 'INFO',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/customized_push/info.log',
- 'backupCount': 3,
- 'maxBytes': 1024 * 1024 * 2 * 100, # 100M
- 'formatter': 'standard',
- 'encoding': 'utf-8',
- },
- 'error_info': {
- 'level': 'INFO',
- 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler',
- 'filename': BASE_DIR + '/static/log/error_info/info.log',
- 'backupCount': 3,
- 'maxBytes': 1024 * 1024 * 2 * 100, # 100M
- 'formatter': 'standard',
- 'encoding': 'utf-8',
- },
- },
- 'loggers': {
- 'django': {
- 'handlers': ['default', 'console'],
- 'level': 'ERROR',
- 'propagate': False
- },
- # log 调用时需要当作参数传入
- 'info': {
- 'handlers': ['info'],
- 'level': 'INFO',
- 'propagate': False
- },
- 'time': {
- 'handlers': ['time'],
- 'level': 'INFO',
- 'propagate': False
- },
- 'v1_push': {
- 'handlers': ['v1_push'],
- 'level': 'INFO',
- 'propagate': False
- },
- 'customized_push': {
- 'handlers': ['customized_push'],
- 'level': 'INFO',
- 'propagate': False
- },
- 'error_info': {
- 'handlers': ['error_info'],
- 'level': 'INFO',
- 'propagate': False
- },
- }
- }
|