美文网首页
[d-2]django项目的跨域问题的解决

[d-2]django项目的跨域问题的解决

作者: ALLIN5 | 来源:发表于2020-04-14 07:24 被阅读0次

    使用说明

    使用django-cors-headers扩展来解决后端对跨域访问的支持。

    文档链接:https://github.com/adamchainz/django-cors-headers

    1.安装

    pip install django-cors-headers
    

    2.添加应用

    INSTALLED_APPS = (
        ...
        'corsheaders',
        ...
    )
    

    3.中间层设置

    MIDDLEWARE = [
        'corsheaders.middleware.CorsMiddleware',
        ...
    ]
    

    4.添加白名单

    # CORS
    CORS_ORIGIN_WHITELIST = (
        '127.0.0.1:8080',
        'localhost:8080',
        '添加需要开放的ip和端口号',
    )
    CORS_ALLOW_CREDENTIALS = True  # 允许携带cookie
    

    相关文章

      网友评论

          本文标题:[d-2]django项目的跨域问题的解决

          本文链接:https://www.haomeiwen.com/subject/myvamhtx.html