"""
Django settings for ProjectPrictice project.
Generated by 'django-admin startproject' using Django 3.0.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/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/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4roz-k6)(!$ql11ocuv%*grfo8)ogz5dm1eg43s(#m)wr94#5-'
# 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',
'corsheaders', #跨域
'chouti', #应用
'chouti.templatetags', #模板
'newapp', #应用
'newappagin',#应用
'rest_framework', #框架
'debug_toolbar', #工具
'django_filters' #过滤器
# 'blog.apps.BlogpConfig',
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'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 = 'ProjectPrictice.urls'
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
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',
'django.template.context_processors.media',
'chouti.tools.context_processors.index',
],
'libraries': {
"my_tag": "chouti.templatetags.my_tag",
},
},
},
]
WSGI_APPLICATION = 'ProjectPrictice.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
#
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# 'default':{
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'crmdata', # 你的数据库名称
# 'USER': 'root', # 你的数据库用户名
# 'PASSWORD': '123456', # 你的数据库密码
# 'HOST': '127.0.0.1', # 你的数据库主机,留空默认为localhost
# 'PORT': '3306', # 你的数据库端口
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/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/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
REST_FRAMEWORK = {
# 配置响应数据格式
# 'DEFAULT_RENDERER_CLASSES':[
# 'rest_framework.renderers.JSONRenderer',
# 'rest_framework.renderers.BrowsableAPIRenderer',
# ],
# 限流配置
# 'DEFAULT_THROTTLE_CLASSES': (
# 'rest_framework.throttling.AnonRateThrottle', # 匿名用户,未登录的
# 'rest_framework.throttling.UserRateThrottle' # 经过登录之后的用户
# ),
# 'DEFAULT_THROTTLE_RATES': {
# 'anon': '2/minute',
# 'user': '5/minute',
# },
# # 自定义认证类路径
"DEFAULT_AUTHENTICATION_CLASSES": [
#
# "rest_framework.authentication.BasicAuthentication,",
# "rest_framework.authentication.SessionAuthentication",
],
#配置过滤
"DEFAULT_FILTER_BACKENDS": [
'django_filters.rest_framework.DjangoFilterBackend'
],
# 权限定义
"DEFAULT_PERMISSION_CLASSES": [
# 'rest_framework.permissions.AllowAny',
],
#全局使用分页
# "rest_framework.pagination.PageNumberPagination",
# "PAGE_SIZE":100
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
# # 自定义权限类路径,这里是使用的默认的,自定义的可以把路径写在这里
# "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
#定义捕获异常 (自定义)
'EXCEPTION_HANDLER':'chouti.exception.exception_handeler_heleper',
#定义捕获异常 (未定义)
# 'EXCEPTION_HANDLER':'rest_framework.views.exception_handeler_heleper',
#版本控制器
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
'DEFAULT_VERSION': 'v1', # 默认的版本
'ALLOWED_VERSIONS': ['v1', 'v2'], # 有效的版本
'VERSION_PARAM': 'version', # 版本的参数名与URL conf中一致
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS=(
os.path.join(BASE_DIR, 'static'),
)
APPEND_SLASH = False
MEDIA_URL = '/file/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'file')
CACHES={
'default':{
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(BASE_DIR,'cache'),
}
}
DEBUG = True
INTERNAL_IPS = [
# ...
'127.0.0.1',
# ...
]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG' if DEBUG else 'INFO',
},
},
}
ps:请注意看添加备注的地方
Django项目实践配置详解
本文档详细介绍了如何配置一个Django项目,包括快速启动设置、应用定义、中间件配置、模板选项、数据库设置等内容。此外,还特别关注了跨域处理、REST框架集成及异常处理等高级特性。
898

被折叠的 条评论
为什么被折叠?



