INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework', # 导入rest_framework 模块
'rest_framework.authtoken', # 用于前后端分离,携带token
'django_filters', #django 默认打开 但是以防万一 最好添加上
'corsheaders', # 跨域问题
'computerapp.apps.ComputerappConfig',
'userapp.apps.UserappConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# corsheaders[跨域设置] 注意位置
'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',
]
REST_FRAMEWORK = {
# 分页
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', # LimitOffsetPagination 分页风格
'PAGE_SIZE': 3, # 每页多少条记录
# 设置权限 还有很多种,可以自己查阅
'DEFAULT_PERMISSION_CLASSES':[
'rest_framework.permissions.IsAdminUser',
],
# 身份验证权限
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
}
CORS_ALLOW_CREDENTIALS = True # 允许携带cookie