zoukankan      html  css  js  c++  java
  • django-restframework settings 内设置及功能

    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







  • 相关阅读:
    mybatis:mybatis再总结
    shiro:RememberMe
    shiro:session管理
    shiro:缓存管理
    shiro:授权管理
    shiro:密码加密(加密、加盐加密)
    spring:spring再总结(ioc、aop、DI等)
    SpringBoot:整合layui、退出功能
    layui:内置模块(日期与时间、数据表格)
    nuxtjs中配置配置env
  • 原文地址:https://www.cnblogs.com/ifiwant/p/13253083.html
Copyright © 2011-2022 走看看