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.
157 lines
4.0 KiB
157 lines
4.0 KiB
from pathlib import Path |
|
import os |
|
from datetime import timedelta |
|
|
|
# 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/3.1/howto/deployment/checklist/ |
|
|
|
# SECURITY WARNING: keep the secret key used in production secret! |
|
SECRET_KEY = 'anzf7gliowvl)d!_fsrgn@3(xf4v#s%2a0ci$57rra7jkfu(17' |
|
|
|
# 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', |
|
'article', |
|
'user_info', |
|
'django_filters', |
|
'comment', |
|
'corsheaders' |
|
] |
|
|
|
MIDDLEWARE = [ |
|
'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 = 'drf_vue_blog.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 = 'drf_vue_blog.wsgi.application' |
|
|
|
|
|
# Database |
|
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases |
|
|
|
DATABASES = { |
|
'default': { |
|
'ENGINE': 'django.db.backends.sqlite3', |
|
'NAME': BASE_DIR / 'db.sqlite3', |
|
} |
|
} |
|
|
|
|
|
# Password validation |
|
# https://docs.djangoproject.com/en/3.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/3.1/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.1/howto/static-files/ |
|
|
|
STATIC_URL = '/static/' |
|
|
|
# 使用django_rest_framework中的分页功能 |
|
REST_FRAMEWORK = { |
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', |
|
# 每页5条记录 |
|
'PAGE_SIZE': 5, |
|
# 使用django-filter后端过滤引擎 |
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], |
|
'DEFAULT_AUTHENTICATION_CLASSES': ( |
|
'rest_framework_simplejwt.authentication.JWTAuthentication', |
|
), |
|
} |
|
|
|
# 媒体文件 |
|
MEDIA_URL = '/media/' |
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') |
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
|
|
|
# simple_jwt配置 |
|
|
|
SIMPLE_JWT = { |
|
'ACCESS_TOKEN_LIFETIME': timedelta(days=1), # 令牌有效时间为1天 |
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=10), # 令牌每10天刷新一次 |
|
} |
|
|
|
|
|
#将允许将cookie包含在跨站点HTTP请求中 |
|
CORS_ALLOW_CREDENTIALS = True |
|
#添加允许执行跨站点请求的主机,为True,则将不使用白名单,并且将接受所有来源 |
|
CORS_ORIGIN_ALLOW_ALL = True |
|
# 允许所有的请求头 |
|
CORS_ALLOW_HEADERS = ('*') |
|
|
|
CORS_ALLOWED_ORIGINS = ( |
|
'http://127.0.0.1:8080', |
|
'http://localhost:8080' |
|
)
|
|
|