123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- """
- Django settings for TestLaboratory project.
- Generated by 'django-admin startproject' using Django 3.2.
- 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/
- """
- import datetime
- from pathlib import Path
- import sys
- import os
- # Build paths inside the project like this: BASE_DIR / 'subdir'.
- # import apps.user.middleware.authentication
- BASE_DIR = Path(__file__).resolve().parent.parent
- sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
- MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
- MEDIA_URL = '/media/'
- SOFTWARE_ROOT = "static/software/"
- PLAN_ROOT = "static/plan-statement/"
- TASK_ROOT = 'static/task-statement/'
- CASE_TEMPLATE_ROOT = 'static/case-template/测试用例模版.xlsx'
- CASE_FILE_ROOT = 'static/case-file/'
- CASE_FILE_EXPORT = 'static/case-file-export/'
- USER_FILE_ROOT = 'static/user-file-export/'
- HTTP_HEAD = 'http://172.26.0.14:8003/'
- # 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-zo64fvv02msf-se7!dek5*w$17#3nh6zta#!i=79bt9d#f88@i'
- # SECURITY WARNING: don't run with debug turned on in production!
- DEBUG = True
- ALLOWED_HOSTS = ['*']
- # AUTH_USER_MODEL = "user.User"
- # AUTHENTICATION_BACKENDS = (
- # 'user.middleware.authentication.CustomBackend',
- # )
- # 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',
- 'corsheaders',
- 'user',
- 'software',
- 'plan',
- 'apps.task',
- 'file',
- 'log',
- 'group',
- 'company'
- ]
- MIDDLEWARE = [
- 'django.middleware.security.SecurityMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.common.CommonMiddleware',
- # 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
- 'corsheaders.middleware.CorsMiddleware',
- 'django.middleware.common.CommonMiddleware',
- ]
- ROOT_URLCONF = 'TestLaboratory.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 = 'TestLaboratory.wsgi.application'
- # Database
- # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'OPTIONS': {
- 'read_default_file': 'Config/database_mysql.cnf',
- },
- }
- }
- # 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',
- },
- ]
- REST_FRAMEWORK = {
- 'DEFAULT_PERMISSION_CLASSES': (
- 'rest_framework.permissions.IsAuthenticated'
- ),
- 'DEFAULT_AUTHENTICATION_CLASSES': (
- 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
- 'rest_framework.authentication.BasicAuthentication',
- 'rest_framework.authentication.SessionAuthentication'
- )
- }
- JWT_AUTH = {
- # 设置token有效时间
- 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=60 * 60 * 2)
- }
- # Internationalization
- # https://docs.djangoproject.com/en/3.2/topics/i18n/
- LANGUAGE_CODE = 'en-us'
- 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/'
- STATICFILES_DIRS = [
- os.path.join(BASE_DIR, "static"),
- ]
- # Default primary key field type
- # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
- DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
- REST_FRAMEWORK = {
- "DEFAULT_AUTHENTICATION_CLASSES": ["apps.user.middleware.authentication.JwtAutentication"]
- }
- CORS_ALLOW_CREDENTIALS = True
- CORS_ORIGIN_ALLOW_ALL = True
- CORS_ALLOW_METHODS = (
- 'GET',
- 'POST',
- 'PUT',
- 'PATCH',
- 'DELETE',
- 'OPTIONS'
- )
- CORS_ALLOW_HEADERS = (
- 'x-requested-with',
- 'content-type',
- 'accept',
- 'origin',
- 'authorization',
- 'x-csrftoken'
- )
- import time
- cur_path = os.path.dirname(os.path.realpath(__file__)) # log_path是存放日志的路径
- log_path = os.path.join(os.path.dirname(cur_path), 'logs')
- if not os.path.exists(log_path): os.mkdir(log_path) # 如果不存在这个logs文件夹,就自动创建一个
- LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'formatters': {
- # 日志格式
- 'standard': {
- 'format': '[%(levelname)s] [%(asctime)s] [%(filename)s:%('
- 'lineno)d] [%(module)s:%(funcName)s] '
- '- %(message)s'},
- 'simple': { # 简单格式
- 'format': '%(levelname)s %(message)s'
- },
- },
- # 过滤
- 'filters': {
- 'require_debug_true': {
- '()': 'django.utils.log.RequireDebugTrue', # 过滤掉调试信息
- },
- },
- # 定义具体处理日志的方式
- 'handlers': {
- # 默认记录所有日志
- 'default': {
- 'level': 'INFO',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'all-{}.log'.format(
- time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 300, # 文件大小
- 'backupCount': 10, # 备份数
- 'formatter': 'standard', # 输出格式
- 'encoding': 'utf-8', # 设置默认编码,否则打印出来汉字乱码
- },
- # 输出错误日志
- 'error': {
- 'level': 'ERROR',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'error-{}.log'.format(
- time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 5, # 文件大小
- 'backupCount': 5, # 备份数
- 'formatter': 'standard', # 输出格式
- 'encoding': 'utf-8', # 设置默认编码
- },
- # 控制台输出
- 'console': {
- 'level': 'DEBUG',
- 'class': 'logging.StreamHandler',
- 'formatter': 'standard'
- },
- #输出info日志
- 'info': {
- 'level': 'INFO',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(log_path, 'info-{}.log'.format(
- time.strftime('%Y-%m-%d'))),
- 'maxBytes': 1024 * 1024 * 5,
- 'backupCount': 5,
- 'formatter': 'standard',
- 'encoding': 'utf-8', # 设置默认编码
- },
- },
- # 配置用哪几种 handlers 来处理日志
- 'loggers': {
- # 类型 为 django 处理所有类型的日志, 默认调用
- 'django': {
- 'handlers': ['default', 'console'],
- 'level': 'INFO',
- 'propagate': False
- },
- # log 调用时需要当作参数传入
- 'log': {
- 'handlers': ['error', 'info', 'console', 'default'],
- 'level': 'INFO',
- 'propagate': True
- },
- }
- }
- """
- python manage.py runserver 172.16.100.180:8000
- """
|