You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
211 lines
6.5 KiB
211 lines
6.5 KiB
""" |
|
Django settings for myshop_back project. |
|
|
|
Generated by 'django-admin startproject' using Django 4.2.4. |
|
|
|
For more information on this file, see |
|
https://docs.djangoproject.com/en/4.2/topics/settings/ |
|
|
|
For the full list of settings and their values, see |
|
https://docs.djangoproject.com/en/4.2/ref/settings/ |
|
""" |
|
import datetime |
|
from pathlib import Path |
|
import sys, 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/4.2/howto/deployment/checklist/ |
|
|
|
# SECURITY WARNING: keep the secret key used in production secret! |
|
SECRET_KEY = 'django-insecure-^#lmlhqou^)f7s85(r*sa!y%-l=e(us-9n=j%=js)q_byva=x)' |
|
|
|
# SECURITY WARNING: don't run with debug turned on in production! |
|
DEBUG = True |
|
|
|
ALLOWED_HOSTS = [] |
|
|
|
# Application definition |
|
# sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) # 导入包, 不到入的话可以在apps中修改name为apps.name |
|
|
|
INSTALLED_APPS = [ |
|
'django.contrib.admin', |
|
'django.contrib.auth', |
|
'django.contrib.contenttypes', |
|
'django.contrib.sessions', |
|
'django.contrib.messages', |
|
'django.contrib.staticfiles', |
|
'apps.basic', |
|
'apps.goods', |
|
'apps.order', |
|
'apps.user', |
|
'apps.music', |
|
'ckeditor', |
|
'ckeditor_uploader', |
|
'rest_framework', |
|
'django_filters', |
|
'rest_framework_swagger', |
|
'rest_framework.authtoken', |
|
'corsheaders', |
|
] |
|
|
|
MIDDLEWARE = [ |
|
'corsheaders.middleware.CorsMiddleware', |
|
'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', |
|
] |
|
|
|
ROOT_URLCONF = 'myshop_back.urls' |
|
|
|
TEMPLATES = [ |
|
{ |
|
'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
'DIRS': [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 = 'myshop_back.wsgi.application' |
|
|
|
# Database |
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases |
|
|
|
DATABASES = { |
|
'default': { |
|
'ENGINE': 'django.db.backends.mysql', |
|
'NAME': 'django_myshop', |
|
'USER': 'root', |
|
'PASSWORD': 'Sxzgx1209', |
|
'HOST': 'home.rogersun.cn', |
|
'PORT': '3306' |
|
} |
|
} |
|
|
|
# Password validation |
|
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/ |
|
|
|
# LANGUAGE_CODE = 'en-us' |
|
LANGUAGE_CODE = 'zh-hans' |
|
|
|
# TIME_ZONE = 'UTC' |
|
TIME_ZONE = 'Asia/Shanghai' |
|
|
|
USE_I18N = True |
|
|
|
USE_TZ = True |
|
|
|
# Static files (CSS, JavaScript, Images) |
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/ |
|
|
|
STATIC_ROOT = os.path.join(BASE_DIR, '/static') # 需要手动设置static的路径 |
|
STATIC_URL = 'static/' |
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] # 需要手动设置static的路径 |
|
|
|
# Default primary key field type |
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field |
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
|
|
|
CKEDITOR_UPLOAD_PATH = 'upload/full_text' |
|
|
|
""" |
|
遇到此报错后需要修改用户验证的model |
|
ERRORS: |
|
auth.User.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'auth.User.groups' clashes with reverse accessor for 'user.MyUser.groups'. |
|
HINT: Add or change a related_name argument to the definition for 'auth.User.groups' or 'user.MyUser.groups'. |
|
""" |
|
AUTH_USER_MODEL = 'user.Myuser' |
|
|
|
REST_FRAMEWORK = { |
|
# 设置全局渲染模板 |
|
'DEFAULT_RENDERER_CLASSES': ( |
|
# 'rest_framework.renderers.JSONRenderer', |
|
'apps.goods.drf_customer_renderer.CustomRenderer', |
|
'rest_framework.renderers.BrowsableAPIRenderer', |
|
), |
|
# 设置全局分页设置 |
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', |
|
'PAGE_SIZE': 5, |
|
# 设置筛选模板 |
|
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',), |
|
'EXCEPTION_HANDLER': 'common.myexception.my_exception_handler', |
|
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema', |
|
# 验证设置 |
|
# 'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework_simplejwt.authentication.JWTAuthentication',), |
|
# 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',), |
|
} |
|
# JWT_AUTH = { |
|
# 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=3), # 配置过期时间 |
|
# 'JWT_AUTH_HEADER_PREFIX': 'JWT', # 配置Token的前缀 |
|
# 'JWT_ALLOW_REFRESH': False, # 是否允许刷新 |
|
# 'JWT_RESPONSE_PAYLOAD_HANDLER': 'common.myjwt.jwt_response_payload_handler', |
|
# } |
|
# |
|
# SIMPLE_JWT = { |
|
# 'ACCESS_TOKEN_LIFETIME': datetime.timedelta(minutes=30), # token有效时长 |
|
# 'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=1), # token刷新有效时长 |
|
# } |
|
|
|
# 跨域配置 |
|
CORS_ALLOW_CREDENTIALS = True # 跨域时是否携带cookie |
|
CORS_ORIGIN_ALLOW_ALL = True # 指定所有域名都可以访问后端接口 |
|
|
|
CACHES = { |
|
'default': { |
|
'BACKEND': 'django.core.cache.backends.db.DatabaseCache', |
|
'LOCATION': 'my_cache_table', |
|
} |
|
} |
|
|
|
# CACHES = { |
|
# 'default': { |
|
# 'BACKEND': 'django_redis.cache.RedisCache', |
|
# 'LOCATION': 'redis://home.rogersun.cn:6379', |
|
# 'OPTIONS': { |
|
# 'CLIENT_CLASS': 'django_redis.client.DefaultClient', |
|
# 'PASSWORD': 'Sxzgx1209', |
|
# } |
|
# } |
|
# } |
|
|
|
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' |
|
SESSION_CACHE_ALIAS = 'default' |
|
|
|
REST_FRAMEWORK_EXTENSIONS = { |
|
'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60, # 缓存时间60秒 |
|
'DEFAULT_USE_CACHE': 'default', # 默认缓存方式, 对应CACHE中的设置 |
|
}
|
|
|