Django和JEditable:CSRF错误 [英] Django and JEditable: CSRF error

查看:150
本文介绍了Django和JEditable:CSRF错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在Django中使用 Jeditable 插件,并迅速遇到CSRF错误: CSRF验证失败。请求中止。, CSRF令牌丢失或不正确

I started using the Jeditable plugin with Django and quickly ran into a CSRF error: "CSRF verification failed. Request aborted.", "CSRF token missing or incorrect"

在撰写本文时,Jeditable插件似乎最后一次更新是在2008年-在此Django之后的某个时间开始对POST请求要求 CSRF令牌

As of this writing the Jeditable plugin seems have been last updated in 2008--sometime after this Django began requiring CSRF tokens for POST requests.

如何将Django CSRF数据添加到Jeditable中?

How do you add Django CSRF data to Jeditable?

推荐答案

这个问题的答案来了来自 CSRF上类似的可编辑帖子。可以将CSRF令牌添加到 submitdata变量中。

The answer to this question came from a similar jeditable post on CSRF. The CSRF token may be added in the "submitdata" variable.

扩展第一个可写示例类似于Django帖子:

Expanding the 1st jeditable example for a Django post look something like this:

$(document).ready(function() {
   $('.edit').editable('http://www.example.com/save.php', { 
        submitdata : { csrfmiddlewaretoken : "{{ csrf_token }}"}
    });
});

注意,为了显示 csrf_token值而不是整个表单字段,请显示 csrf_token 包裹在{{..}}中,而不是{%..%}中。

Note, in order to show the "csrf_token" value instead of an entire form field, the "csrf_token" is wrapped in {{..}} instead of {% .. %}.

这篇关于Django和JEditable:CSRF错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆