【问题标题】:Django Ajax 403 only when Posting from custom localhost urlDjango Ajax 403 仅在从自定义 localhost url 发布时
【发布时间】:2017-06-16 06:34:33
【问题描述】:

我按照所有说明让 Ajax 与 Django 一起正常工作(ajaxSetup 在每个请求上添加 X-CSRFToken 标头等),现在该部分工作正常。

我正在使用 django-rest-framework、django-allauth 和 rest-auth

我现在正在尝试使用 DRF 测试 Facebook 登录,因为 Facebook 不允许 localhost 成为我编辑的注册应用程序 ~/etc/host 并添加 local.test.com 作为 127.0.0.1 的别名。现在,每当我尝试向 Django 发帖时,我都会再次被禁止 403。我认为这可能与 Request URLRemote Address 不同有关,但我真的不知道如何处理它。

由于我不确定问题出在哪里,我认为在 github 上分享项目链接更有意义:https://github.com/Sebastiansc/Sauti

我该怎么做才能让来自 local.test.com 的 POST Ajax 请求正常工作?

【问题讨论】:

    标签: ajax django xmlhttprequest django-rest-framework django-rest-auth


    【解决方案1】:

    试试@csrf_exempt

    from django.views.decorators.csrf import csrf_exempt
    @csrf_exempt
    def your_view(request):
        print "fff"
        print "do your things..."
    

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 2015-11-06
      • 2021-04-29
      • 2020-11-18
      • 2014-01-25
      • 2019-08-10
      • 1970-01-01
      • 2017-09-22
      相关资源
      最近更新 更多