<bdo id='a9ts0'></bdo><ul id='a9ts0'></ul>

<tfoot id='a9ts0'></tfoot>

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

      1. <i id='a9ts0'><tr id='a9ts0'><dt id='a9ts0'><q id='a9ts0'><span id='a9ts0'><b id='a9ts0'><form id='a9ts0'><ins id='a9ts0'></ins><ul id='a9ts0'></ul><sub id='a9ts0'></sub></form><legend id='a9ts0'></legend><bdo id='a9ts0'><pre id='a9ts0'><center id='a9ts0'></center></pre></bdo></b><th id='a9ts0'></th></span></q></dt></tr></i><div id='a9ts0'><tfoot id='a9ts0'></tfoot><dl id='a9ts0'><fieldset id='a9ts0'></fieldset></dl></div>
        <legend id='a9ts0'><style id='a9ts0'><dir id='a9ts0'><q id='a9ts0'></q></dir></style></legend>
      2. Django 应用程序中的访问控制允许来源

        时间:2023-09-03
        <legend id='0Nx4o'><style id='0Nx4o'><dir id='0Nx4o'><q id='0Nx4o'></q></dir></style></legend>
          <tbody id='0Nx4o'></tbody>
          <tfoot id='0Nx4o'></tfoot>

          <small id='0Nx4o'></small><noframes id='0Nx4o'>

            <bdo id='0Nx4o'></bdo><ul id='0Nx4o'></ul>
            <i id='0Nx4o'><tr id='0Nx4o'><dt id='0Nx4o'><q id='0Nx4o'><span id='0Nx4o'><b id='0Nx4o'><form id='0Nx4o'><ins id='0Nx4o'></ins><ul id='0Nx4o'></ul><sub id='0Nx4o'></sub></form><legend id='0Nx4o'></legend><bdo id='0Nx4o'><pre id='0Nx4o'><center id='0Nx4o'></center></pre></bdo></b><th id='0Nx4o'></th></span></q></dt></tr></i><div id='0Nx4o'><tfoot id='0Nx4o'></tfoot><dl id='0Nx4o'><fieldset id='0Nx4o'></fieldset></dl></div>
                  本文介绍了Django 应用程序中的访问控制允许来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在为基于 Django 的应用程序开发 Phonegap 应用程序,但在尝试进行 Ajax 调用时出现此错误:

                  I'm developing a Phonegap app for my Django based app, but when trying to make Ajax calls I get this error:

                  XMLHttpRequest cannot load http://domain.herokuapp.com/getcsrf/?tags=jquery%2Cjavascript&tagmode=any&format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 
                  

                  我怎样才能让我的 Django 应用程序允许某些 url 跨源?

                  How can I make it so my Django app allows cross origin for some urls?

                  这是我的 Ajax 代码:

                  Here's my Ajax code:

                  get: function() {
                      $.getJSON("http://domain.herokuapp.com/getcsrf/",
                      {
                          tags: "jquery,javascript",
                          tagmode: "any",
                          format: "json"
                      },
                      function(data) {
                          $.each(data.items, function(item){
                              console.log(item);
                              });
                      });
                  }
                  

                  推荐答案

                  默认情况下,Django 不提供提供跨域所需的标头.最简单的方法是使用这个为您处理它的 Django 应用程序:https://github.com/adamchainz/django-cors-headers

                  Django by default does not provide the headers necessary to provide cross origin. The easiest way would be to just use this Django app that handles it for you: https://github.com/adamchainz/django-cors-headers

                  • 添加到已安装的应用中
                  • 添加到中间件
                  • 然后是……
                  CORS_ALLOWED_ORIGINS = [
                      "http://read.only.com",
                      "http://change.allowed.com",
                  ]
                  

                  要支持全部允许,只需使用设置...CORS_ALLOW_ALL_ORIGINS = True然后在中间件或视图中对请求进行任何过滤.

                  to support allowing all, just use the setting... CORS_ALLOW_ALL_ORIGINS = True and then do any filtering of the request in middleware or in the view.

                  这篇关于Django 应用程序中的访问控制允许来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:何时启用 CORS 是安全的? 下一篇:如何检测 JavaScript 中 XMLHttpRequest() 的跨域 (CORS)

                  相关文章

                  最新文章

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

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

                    1. <tfoot id='wOXAk'></tfoot>
                      <legend id='wOXAk'><style id='wOXAk'><dir id='wOXAk'><q id='wOXAk'></q></dir></style></legend>