<small id='hzp8j'></small><noframes id='hzp8j'>

    <tfoot id='hzp8j'></tfoot>
  1. <i id='hzp8j'><tr id='hzp8j'><dt id='hzp8j'><q id='hzp8j'><span id='hzp8j'><b id='hzp8j'><form id='hzp8j'><ins id='hzp8j'></ins><ul id='hzp8j'></ul><sub id='hzp8j'></sub></form><legend id='hzp8j'></legend><bdo id='hzp8j'><pre id='hzp8j'><center id='hzp8j'></center></pre></bdo></b><th id='hzp8j'></th></span></q></dt></tr></i><div id='hzp8j'><tfoot id='hzp8j'></tfoot><dl id='hzp8j'><fieldset id='hzp8j'></fieldset></dl></div>

    <legend id='hzp8j'><style id='hzp8j'><dir id='hzp8j'><q id='hzp8j'></q></dir></style></legend>

        <bdo id='hzp8j'></bdo><ul id='hzp8j'></ul>
    1. 如何在 Django REST 框架上启用 CORS

      时间:2023-07-06
        <tbody id='u3L4p'></tbody>

      1. <tfoot id='u3L4p'></tfoot>
            <bdo id='u3L4p'></bdo><ul id='u3L4p'></ul>

              <legend id='u3L4p'><style id='u3L4p'><dir id='u3L4p'><q id='u3L4p'></q></dir></style></legend>

              <i id='u3L4p'><tr id='u3L4p'><dt id='u3L4p'><q id='u3L4p'><span id='u3L4p'><b id='u3L4p'><form id='u3L4p'><ins id='u3L4p'></ins><ul id='u3L4p'></ul><sub id='u3L4p'></sub></form><legend id='u3L4p'></legend><bdo id='u3L4p'><pre id='u3L4p'><center id='u3L4p'></center></pre></bdo></b><th id='u3L4p'></th></span></q></dt></tr></i><div id='u3L4p'><tfoot id='u3L4p'></tfoot><dl id='u3L4p'><fieldset id='u3L4p'></fieldset></dl></div>

                <small id='u3L4p'></small><noframes id='u3L4p'>

                本文介绍了如何在 Django REST 框架上启用 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何在我的 Django REST 框架上启用 CORS?reference 没有多大帮助,它说我可以通过中间件来做,但我该怎么做呢?

                How can I enable CORS on my Django REST Framework? the reference doesn't help much, it says that I can do by a middleware, but how can I do that?

                推荐答案

                您在问题中引用的链接建议使用 django-cors-headers,其 文档说要安装库

                The link you referenced in your question recommends using django-cors-headers, whose documentation says to install the library

                python -m pip install django-cors-headers
                

                然后将其添加到您安装的应用程序中:

                and then add it to your installed apps:

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

                您还需要添加一个中间件类来监听响应:

                You will also need to add a middleware class to listen in on responses:

                MIDDLEWARE = [
                    ...,
                    'corsheaders.middleware.CorsMiddleware',
                    'django.middleware.common.CommonMiddleware',
                    ...,
                ]
                

                并为 CORS 指定域,例如:

                and specify domains for CORS, e.g.:

                CORS_ALLOWED_ORIGINS = [
                    'http://localhost:3030',
                ]
                

                请浏览其文档的配置部分,特别注意各种 CORS_ORIGIN_ 设置.您需要根据自己的需要设置其中的一些.

                Please browse the configuration section of its documentation, paying particular attention to the various CORS_ORIGIN_ settings. You'll need to set some of those based on your needs.

                这篇关于如何在 Django REST 框架上启用 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Python - 使用 Boto3 从 DynamoDB 检索最大主键值 下一篇:带有 AWS cognito 的无服务器框架生成 CORS 错误

                相关文章

                1. <legend id='CBU7G'><style id='CBU7G'><dir id='CBU7G'><q id='CBU7G'></q></dir></style></legend>
                    <bdo id='CBU7G'></bdo><ul id='CBU7G'></ul>

                2. <i id='CBU7G'><tr id='CBU7G'><dt id='CBU7G'><q id='CBU7G'><span id='CBU7G'><b id='CBU7G'><form id='CBU7G'><ins id='CBU7G'></ins><ul id='CBU7G'></ul><sub id='CBU7G'></sub></form><legend id='CBU7G'></legend><bdo id='CBU7G'><pre id='CBU7G'><center id='CBU7G'></center></pre></bdo></b><th id='CBU7G'></th></span></q></dt></tr></i><div id='CBU7G'><tfoot id='CBU7G'></tfoot><dl id='CBU7G'><fieldset id='CBU7G'></fieldset></dl></div>

                    <small id='CBU7G'></small><noframes id='CBU7G'>

                    <tfoot id='CBU7G'></tfoot>