"""
Django settings for opwf project.
Generated by \'django-admin startproject\' using Django 2.0.13.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import datetime
import os, sys
Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
sys.path.insert(0, os.path.join(BASE_DIR, \'apps\'))
Quick-start development settings - unsuitable for production
See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = \'uorj1ni^mnut@wo@c%)iv)%5=8dxlml4-j0!f3b%4#f*8a5)3t\'
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\',
\'rest_framework\',
\'corsheaders\',
\'user.apps.UserConfig\',
\'workflow.apps.WorkflowConfig\',
\'workerorder.apps.WorkerorderConfig\',
# \'jwt\',
# \'rest_framework_jwt\',
# \'rest_framework.authentication\'
]
MIDDLEWARE = [
\'django.middleware.security.SecurityMiddleware\',
\'django.contrib.sessions.middleware.SessionMiddleware\',
\'django.middleware.common.CommonMiddleware\',
\'corsheaders.middleware.CorsMiddleware\',
# \'django.middleware.csrf.CsrfViewMiddleware\',
\'django.contrib.auth.middleware.AuthenticationMiddleware\',
\'django.contrib.messages.middleware.MessageMiddleware\',
\'django.middleware.clickjacking.XFrameOptionsMiddleware\',
]
ROOT_URLCONF = \'opwf.urls\'
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
\'http://127.0.0.1:8080\',
\'http://localhost:8080\',
)
CORS_ALLOW_CREDENTIALS = True
TEMPLATES = [
{
\'BACKEND\': \'django.template.backends.django.DjangoTemplates\',
\'DIRS\': [],
\'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 = \'opwf.wsgi.application\'
Database
https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
\'default\': {
\'ENGINE\': \'django.db.backends.mysql\',
\'NAME\': \'opwf_db\',
\'USER\': \'root\',
\'PASSWORD\': \'1\',
\'HOST\': \'127.0.0.1\',
\'PORT\': \'3306\'
}
}
Password validation
https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
REST_FRAMEWORK = {
# 文档报错: AttributeError: ‘AutoSchema’ object has no attribute ‘get_link’
# 用下面的设置可以解决
\'DEFAULT_SCHEMA_CLASS\': \'rest_framework.schemas.AutoSchema\',
# 默认设置是:
# \'DEFAULT_SCHEMA_CLASS\': \'rest_framework.schemas.openapi.AutoSchema\',
# 异常处理器
# \'EXCEPTION_HANDLER\': \'user.utils.exception_handler\',
# Base API policies 默认渲染器类
\'DEFAULT_RENDERER_CLASSES\': [
\'rest_framework.renderers.JSONRenderer\',
\'rest_framework.renderers.BrowsableAPIRenderer\',
],
# 默认解析器类
\'DEFAULT_PARSER_CLASSES\': [
\'rest_framework.parsers.JSONParser\',
\'rest_framework.parsers.FormParser\',
\'rest_framework.parsers.MultiPartParser\'
],
# 1.认证器(全局)
\'DEFAULT_AUTHENTICATION_CLASSES\': [
\'rest_framework_jwt.authentication.JSONWebTokenAuthentication\', # 在 DRF中配置JWT认证
# \'rest_framework.authentication.SessionAuthentication\', # 使用session时的认证器
# \'rest_framework.authentication.BasicAuthentication\' # 提交表单时的认证器
],
# 2.权限配置(全局): 顺序靠上的严格
\'DEFAULT_PERMISSION_CLASSES\': [
# \'rest_framework.permissions.IsAdminUser\', # 管理员可以访问
# \'rest_framework.permissions.IsAuthenticated\', # 认证用户可以访问
# \'rest_framework.permissions.IsAuthenticatedOrReadOnly\', # 认证用户可以访问, 否则只能读取
\'rest_framework.permissions.AllowAny\', # 所有用户都可以访问
],
# 3.限流(防爬虫)
\'DEFAULT_THROTTLE_CLASSES\': [
\'rest_framework.throttling.AnonRateThrottle\',
\'rest_framework.throttling.UserRateThrottle\',
],
# 3.1限流策略
# \'DEFAULT_THROTTLE_RATES\': {
# \'user\': \'100/hour\', # 认证用户每小时100次
# \'anon\': \'300/day\', # 未认证用户每天能访问3次
# },
\'DEFAULT_CONTENT_NEGOTIATION_CLASS\': \'rest_framework.negotiation.DefaultContentNegotiation\',
\'DEFAULT_METADATA_CLASS\': \'rest_framework.metadata.SimpleMetadata\',
\'DEFAULT_VERSIONING_CLASS\': None,
# 4.分页(全局):全局分页器, 例如 省市区的数据自定义分页器, 不需要分页
# \'DEFAULT_PAGINATION_CLASS\': \'rest_framework.pagination.PageNumberPagination\',
# # 每页返回数量
# \'PAGE_SIZE\': 3,
# 5.过滤器后端
\'DEFAULT_FILTER_BACKENDS\': [
\'django_filters.rest_framework.DjangoFilterBackend\',
# \'django_filters.rest_framework.backends.DjangoFilterBackend\', 包路径有变化
],
# 5.1过滤排序(全局):Filtering 过滤排序
\'SEARCH_PARAM\': \'search\',
\'ORDERING_PARAM\': \'ordering\',
\'NUM_PROXIES\': None,
# 6.版本控制:Versioning 接口版本控制
\'DEFAULT_VERSION\': None,
\'ALLOWED_VERSIONS\': None,
\'VERSION_PARAM\': \'version\',
# Authentication 认证
# 未认证用户使用的用户类型
\'UNAUTHENTICATED_USER\': \'django.contrib.auth.models.AnonymousUser\',
# 未认证用户使用的Token值
\'UNAUTHENTICATED_TOKEN\': None,
# View configuration
\'VIEW_NAME_FUNCTION\': \'rest_framework.views.get_view_name\',
\'VIEW_DESCRIPTION_FUNCTION\': \'rest_framework.views.get_view_description\',
\'NON_FIELD_ERRORS_KEY\': \'non_field_errors\',
# Testing
\'TEST_REQUEST_RENDERER_CLASSES\': [
\'rest_framework.renderers.MultiPartRenderer\',
\'rest_framework.renderers.JSONRenderer\'
],
\'TEST_REQUEST_DEFAULT_FORMAT\': \'multipart\',
# Hyperlink settings
\'URL_FORMAT_OVERRIDE\': \'format\',
\'FORMAT_SUFFIX_KWARG\': \'format\',
\'URL_FIELD_NAME\': \'url\',
# Encoding
\'UNICODE_JSON\': True,
\'COMPACT_JSON\': True,
\'STRICT_JSON\': True,
\'COERCE_DECIMAL_TO_STRING\': True,
\'UPLOADED_FILES_USE_URL\': True,
# Browseable API
\'HTML_SELECT_CUTOFF\': 1000,
\'HTML_SELECT_CUTOFF_TEXT\': "More than {count} items...",
# Schemas
\'SCHEMA_COERCE_PATH_PK\': True,
\'SCHEMA_COERCE_METHOD_NAMES\': {
\'retrieve\': \'read\',
\'destroy\': \'delete\'
},
# \'Access-Control-Allow-Origin\':\'http://localhost:8080\',
# \'Access-Control-Allow-Credentials\': True
}
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.0/topics/i18n/
LANGUAGE_CODE = \'zh-hans\'
TIME_ZONE = \'Asia/Shanghai\'
USE_I18N = True
USE_L10N = True
USE_TZ = False
Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = \'/static/\'
AUTH_USER_MODEL = \'user.User\'
jwt载荷中的有效期设置
JWT_AUTH = {
# 1.token前缀:headers中 Authorization 值的前缀
\'JWT_AUTH_HEADER_PREFIX\': \'JWT\',
# 2.token有效期:一天有效
\'JWT_EXPIRATION_DELTA\': datetime.timedelta(days=1),
# 3.刷新token:允许使用旧的token换新token
\'JWT_ALLOW_REFRESH\': True,
# 4.token有效期:token在24小时内过期, 可续期token
\'JWT_REFRESH_EXPIRATION_DELTA\': datetime.timedelta(hours=24),
# 5.自定义JWT载荷信息:自定义返回格式,需要手工创建
\'JWT_RESPONSE_PAYLOAD_HANDLER\': \'user.utils.jwt_response_payload_handler\',
}