回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我在Django框架中使用JqGrid。这是JS:</p>
<pre><code> jQuery("#list").jqGrid({
url:'{% url views.manage.devicesajax %}',
datatype: 'json',
mtype: 'GET',
colNames:['DID', 'UDID', 'Owner', 'Name', 'First seen', 'Last seen'],
colModel :[
{name:'did', index:'did', width: 30, searchoptions:{sopt:['eq','ne','bw','cn']}},
{name:'udid', index:'udid', width: 120, editable: true, searchoptions:{sopt:['eq','ne','bw','cn']}},
{name:'d_owner', index:'d_owner', width: 70, editable: true, searchoptions:{sopt:['eq','ne','bw','cn']}},
{name:'d_name', index:'d_name', editable: true, searchoptions:{sopt:['eq','ne','bw','cn']}},
{name:'d_firstseen', index:'d_firstseen', width: 80},
{name:'d_lastseen', index:'d_lastseen', width: 80}],
pager: jQuery('#pager'),
rowNum:20,
rowList:[20,50,100],
sortname: 'did',
sortorder: "desc",
multiselect: true,
viewrecords: true,
imgpath: 'themes/basic/images',
caption: 'Devices list',
height: 330,
width: 1000,
onSelectRow: function(id) {
var id = $("#list").getRowData(id).message_id;
message_id = id;
},
editurl: "{% url views.manage.deviceseditajax %}"
});
</code></pre>
<p>当我在JqGrid中编辑行时,我从editurl得到错误:</p>
<blockquote>
<p>Forbidden (403)
CSRF verification failed. Request aborted.</p>
</blockquote>
<p>这是因为csrf_令牌不会与其他数据一起传递给editurl。
如何将csrf_令牌添加到editurl的POST请求中?在</p>
<p>这段代码运行得很好(完整的jqgrid init):</p>
^{pr2}$