• django 允许跨域请求


    django允许跨域请求配置

    下载corsheader

    pip install django-cors-headers

    修改setting.py中配置

    在INSTALLED_APPS中增加corsheaders

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        
        'corsheaders',
    ]
    
    MIDDLEWARE_CLASSES = [
        '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.auth.middleware.SessionAuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]
    CORS_ORIGIN_ALLOW_ALL = True
    CORS_ALLOW_CREDENTIALS = True
    CORS_ORIGIN_ALLOW_ALL = True
    CORS_ORIGIN_WHITELIST = (
        '*'
    )
    CORS_ALLOW_METHODS = (
        'DELETE',
        'GET',
        'OPTIONS',
        'PATCH',
        'POST',
        'PUT',
        'VIEW',
    )
    
    CORS_ALLOW_HEADERS = (
        'XMLHttpRequest',
        'X_FILENAME',
        'accept-encoding',
        'authorization',
        'content-type',
        'dnt',
        'origin',
        'user-agent',
        'x-csrftoken',
        'x-requested-with',
    )
    其他配置选项
  • 相关阅读:
    Java绘出pdf实现方法
    Java设置字体颜色
    猜测分箱算法
    获取图片存储到本地
    input(file)异步上传文件
    物流轨迹抓取
    bootstrap 模态框
    从数组中随机选择一个数
    spring cron表达式
    mabtis批量修改
  • 原文地址:https://www.cnblogs.com/modengdai/p/10810609.html
Copyright © 2020-2023  润新知