weixin_33725126 2018-09-29 12:33 采纳率: 0%
浏览 86

Django文件上传Ajax

I am trying to upload a file in Django using Ajax. I have tried different approaches but I've get same results. The file cannot be read in the view.

Here is my codes:

#JS
$("#upload-file").click(function() {
var data = new FormData($('#fileForm').get(0));
var csrftoken = getCookie('csrftoken');
$.ajax({
type: "POST",
headers: {'X-CSRFToken': csrftoken},
url: "/countwords/",
data: data,
cache: false,
processData: false,
contentType: false,
success: function(json) {

    var ss = json.len;

    alert(ss);},

error: function() {

    alert('error');}

});
});

finally here is my view codes:

if request.method == 'POST':
    print request.FILES.keys()
    print request.FILES
    print request.POST.keys()

But I get following output when the code is run:

[]
MultiValueDict: {}
[]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器