发布于 2024-12-03 09:30:24 字数 8 浏览 1 评论 0原文

continue

I'm trying to use an ajax request to call a function in a different view, but I'm getting a 403 error.

excerpt from my template:

    FB.ui({ method: 'apprequests', title: 'Invite your friends to answer questions!', message:'Invite your friends!'},
    function(response) {
        jQuery.ajax({
            url: "/canvas/request/",
            type: "post",
            data: {qid: {{ qid }} , request_ids: response.request_ids}
        })
    });

excerpt from my view:

def save_request(request):
    print("in save request")
    for id in request.request_ids:
        share = ShareRequest
        share.question = request.qid
        share.share_id = id
        share.save()

excerpt from my urls:

urlpatterns = patterns(...
    (r'^request/', save_request),

returns [06/Sep/2011 13:35:56] "POST /canvas/request/ HTTP/1.1" 403 2332

I'm really confused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-12-10 09:30:24

Perhaps you need to add the CSRF token to your request? Some details are at https://docs.djangoproject.com/en/dev/ref/contrib/csrf/.

Smile简单爱 2024-12-10 09:30:24

BAD but QUICK solution for keep yourself not in the stealth mode:

from django.views.decorators.csrf import csrf_exempt

use this @csrf_exempt decorator at your views to ignore the csrf issue.

但这是一个坏习惯。因此,请确保您的网站 csrf 受到保护。 And follow the django documentation.

BAD but QUICK solution for keep yourself not in the stealth mode:

from django.views.decorators.csrf import csrf_exempt

use this @csrf_exempt decorator at your views to ignore the csrf issue.

But This is a bad habbit. So make sure your sites csrf protected. And follow the django documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文