码迷,mamicode.com
首页 > 其他好文 > 详细

Django settings 描述

时间:2020-10-21 20:54:52      阅读:19      评论:0      收藏:0      [点我收藏+]

标签:中文   zone   https   防止   smi   消息   网站   filename   byte   

"""
Django settings for log_collect_statistics project.

Generated by ‘django-admin startproject‘ using Django 2.1.15.

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

# 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 = ‘--1k(694cyc_6s7r=7!hp25km_2*hp^j$b&hm(3%+ydq68_se4‘

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = False

# 允许所有域名访问
ALLOWED_HOSTS = ["*"]


# Application definition

# App列表
INSTALLED_APPS = [
    ‘django.contrib.admin‘,  # 内置后台管理系统
    ‘django.contrib.auth‘,  # 内置用户认证系统
    ‘django.contrib.contenttypes‘,  # 记录项目中所有的model元数组(Django 的 ORM框架)
    ‘django.contrib.sessions‘,  # session会话功能, 用于标识当前访问网站用户身份,记录像相关用户信息
    ‘django.contrib.messages‘,  # 消息提示功能
    ‘django.contrib.staticfiles‘,  # 查询静态资源路径
    ‘app.apps.AppConfig‘,
    ‘user.apps.UserConfig‘,
]

# 中间件
MIDDLEWARE = [
    ‘django.middleware.security.SecurityMiddleware‘,  # 内置的安全机制,保护用户与网站的通信安全
    ‘django.contrib.sessions.middleware.SessionMiddleware‘,  # 会话session功能
    ‘django.middleware.locale.LocaleMiddleware‘,  # 使用中文
    ‘django.middleware.common.CommonMiddleware‘,  # 处理请求信息,规范化请求内容
    ‘django.middleware.csrf.CsrfViewMiddleware‘,  # 开启CSRF防护功能
    ‘django.contrib.auth.middleware.AuthenticationMiddleware‘,  # 开启内置的用户认证系统
    ‘django.contrib.messages.middleware.MessageMiddleware‘,  # 开启内置的信息提示功能
    ‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,  # 防止恶意程序点击劫持
    ‘log_collect_statistics.middlewares.cors.Mymiddle‘,
    ‘log_collect_statistics.middlewares.ExceptionLoggingMiddleware.ExceptionLoggingMiddleware‘,
]

ROOT_URLCONF = ‘log_collect_statistics.urls‘

# 模板配置
TEMPLATES = [
    {
        ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,  # 定义模板引擎,用于识别模板里面的变量和指令
        ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘), ],  # 设置模板所在路径
        ‘APP_DIRS‘: True,  # 是否在APP里面查找模板文件
        ‘OPTIONS‘: {  # 用于填充在RequestContext中上下文的调用函数,一般情况不做任何修改
            ‘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 = ‘log_collect_statistics.wsgi.application‘


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

# 数据库配置
if DEBUG:
    DATABASES = {
        ‘default‘: {
            ‘ENGINE‘: ‘django.db.backends.mysql‘,  # 链接数据库的类型
            ‘NAME‘: ‘log_collect‘,  # 链接数据库的名字
            ‘HOST‘: ‘192.168.10.5‘,  # 数据库主机地址
            ‘PORT‘: 3306,  # 数据库端口
            ‘USER‘: ‘wzy‘,  # 数据库用户名
            ‘PASSWORD‘: ‘root1234‘,  # 数据库密码
        },
        ‘my_sqlite3‘: {
            ‘ENGINE‘: ‘django.db.backends.sqlite3‘,  # 链接数据库的类型
            ‘NAME‘: os.path.join(BASE_DIR, ‘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/

LANGUAGE_CODE = ‘en-us‘

# 时区配置
# TIME_ZONE = ‘UTC‘
TIME_ZONE = ‘Asia/Shanghai‘

USE_I18N = True

USE_L10N = True

USE_TZ = True

# 配置自定义用表 MyUser
AUTH_USER_MODEL = ‘user.MyUser‘


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

# 默认静态文件在app的static目录下  是app列表中django.contrib.staticfiles实现的
STATIC_URL = ‘/static/‘

# 在服务器上部署,实现服务器和项目之间的映射,主要是收集整个项目的静态资源,并存放在一个新的文件夹,然后由该文件与服务器之间构建映射关系
# 主要用于项目部署
# STATIC_ROOT = os.path.join(BASE_DIR, ‘all_static‘),

# 将静态文件配置在系统根目录下
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, ‘static‘),
]

# rabbitMq 的配置信息
if DEBUG:
    RABBIT_HOST = ‘192.168.10.10‘
    QUEUE_TOPIC = ‘logs‘
    RABBIT_USERNAME = ‘wzy‘
    RABBIT_PASSWORD = ‘root1234‘
else:
    RABBIT_HOST = ‘192.168.10.10‘
    QUEUE_TOPIC = ‘logs‘
    RABBIT_USERNAME = ‘wzy‘
    RABBIT_PASSWORD = ‘root1234‘

LOG_ROOT = os.path.join(BASE_DIR, ‘logs‘) + os.sep
# 日志存储路径
if DEBUG:
    # 日志记录
    LOGGING = {
        ‘version‘: 1,
        ‘disable_existing_loggers‘: False,
        ‘formatters‘: {
           ‘standard‘: {
               ‘format‘: ‘%(asctime)s [%(name)s:%(lineno)d][%(module)s:%(funcName)s] [%(levelname)s]- %(message)s‘},
        },
        ‘handlers‘: {
            ‘console‘: {
                ‘level‘: ‘DEBUG‘,
                ‘class‘: ‘logging.StreamHandler‘,
            },
            ‘file‘: {
                ‘level‘: ‘DEBUG‘,
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘all.log‘,
                ‘maxBytes‘: 1024*1024*5,                  # 文件大小
                ‘backupCount‘: 10,                         # 备份份数
                ‘formatter‘: ‘standard‘,
            },
            ‘info‘: {
                ‘level‘: ‘INFO‘,
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘info.log‘,
                ‘maxBytes‘: 1024*1024*5,                  # 文件大小
                ‘backupCount‘: 10,                         # 备份份数
                ‘formatter‘: ‘standard‘,
            },
            ‘error‘: {
                ‘level‘: ‘WARNING‘,
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘error.log‘,
                ‘maxBytes‘: 1024*1024*5,                  # 文件大小
                ‘backupCount‘: 10,                         # 备份份数
                ‘formatter‘: ‘standard‘,
            },
        },
        # 字别的模块中使用使用  import logging   logger = logging.getLogger(‘django‘)   getLogger 中的变量为 以下配置中内容
        ‘loggers‘: {
            ‘django‘: {
                ‘handlers‘: [‘file‘, ‘console‘],
                ‘propagate‘: True,
            },
            ‘inf‘: {
                ‘handlers‘: [‘info‘, ‘console‘],
                ‘level‘: ‘INFO‘,
                ‘propagate‘: True,
            },
            ‘err‘: {
                ‘handlers‘: [‘error‘, ‘console‘],
                ‘level‘: ‘WARNING‘,
                ‘propagate‘: True,
            },
            # 查看数据库执行代码
            ‘django.db.backends‘: {
                ‘handlers‘: [‘console‘, ],
                ‘propagate‘: True,
                ‘level‘: ‘DEBUG‘,
            },
        },
    }

else:
    # 日志记录
    LOGGING = {
        ‘version‘: 1,
        ‘disable_existing_loggers‘: False,
        ‘formatters‘: {
            ‘standard‘: {
                ‘format‘: ‘%(asctime)s [%(name)s:%(lineno)d][%(module)s:%(funcName)s] [%(levelname)s]- %(message)s‘},
        },
        ‘handlers‘: {
            ‘console‘: {
                ‘level‘: ‘INFO‘,  # DEBUG
                ‘class‘: ‘logging.StreamHandler‘,
            },
            ‘file‘: {
                ‘level‘: ‘INFO‘,  # DEBUG
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘all.log‘,
                ‘maxBytes‘: 1024 * 1024 * 5,  # 文件大小
                ‘backupCount‘: 10,  # 备份份数
                ‘formatter‘: ‘standard‘,
            },
            ‘info‘: {
                ‘level‘: ‘INFO‘,
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘info.log‘,
                ‘maxBytes‘: 1024 * 1024 * 5,  # 文件大小
                ‘backupCount‘: 10,  # 备份份数
                ‘formatter‘: ‘standard‘,
            },
            ‘error‘: {
                ‘level‘: ‘WARNING‘,
                ‘class‘: ‘logging.handlers.RotatingFileHandler‘,
                ‘filename‘: LOG_ROOT + ‘error.log‘,
                ‘maxBytes‘: 1024 * 1024 * 5,  # 文件大小
                ‘backupCount‘: 10,  # 备份份数
                ‘formatter‘: ‘standard‘,
            },
        },
        # 字别的模块中使用使用  import logging   logger = logging.getLogger(‘django‘)   getLogger 中的变量为 以下配置中内容
        ‘loggers‘: {
            ‘django‘: {
                ‘handlers‘: [‘file‘, ‘console‘],
                ‘propagate‘: True,
            },
            ‘inf‘: {
                ‘handlers‘: [‘info‘, ‘console‘],
                ‘level‘: ‘INFO‘,
                ‘propagate‘: True,
            },
            ‘err‘: {
                ‘handlers‘: [‘error‘, ‘console‘],
                ‘level‘: ‘WARNING‘,
                ‘propagate‘: True,
            },
            # 查看数据库执行代码
            ‘django.db.backends‘: {
                ‘handlers‘: [‘console‘, ],
                ‘propagate‘: True,
                ‘level‘: ‘DEBUG‘,
            },
        },
    }

  

Django settings 描述

标签:中文   zone   https   防止   smi   消息   网站   filename   byte   

原文地址:https://www.cnblogs.com/xiao-xue-di/p/13851483.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!