zoukankan      html  css  js  c++  java
  • django中配置允许跨域请求

    对于django

    安装django-cors-headers,详情请看官方文档

    pip install django-cors-headers
    

      

    配置settings.py文件

    a.在INSTALLED_APPS里添加“corsheaders”

    INSTALLED_APPS = [
        ...
        'corsheaders',
        ...
     ] 
    

      

    b.在MIDDLEWARE_CLASSES添加 ‘corsheaders.middleware.CorsMiddleware’, ‘django.middleware.common.CommonMiddleware’

    MIDDLEWARE_CLASSES = (
        ...
        'corsheaders.middleware.CorsMiddleware',
        'django.middleware.common.CommonMiddleware', 
        ...
    )
    

      

    c.在sitting.py底部添加

    #跨域增加忽略
    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 = (
        'accept',
        'accept-encoding',
        'authorization',
        'content-type',
        'dnt',
        'origin',
        'user-agent',
        'x-csrftoken',
        'x-requested-with',
    )
    

      

  • 相关阅读:
    软件工程课程设计团队项目总结与项目报告
    个人总结
    团队项目UI
    黄金点
    wordcount
    小学运算
    第七周
    第八周
    第六周博客
    第五周博客
  • 原文地址:https://www.cnblogs.com/randomlee/p/9752705.html
Copyright © 2011-2022 走看看