イメージをHTMLページからDjangoビューに送信しようとしています。しかし、私はデータを得ることができません。以下は私のコードです。jQueryを使用して入力フィールドからイメージを取得する方法
<input type="file" id = "imageupload" onchange = "sendimg()" />
<script>
var sendimg = function(){
var img = document.getElementById("imageupload")
$.ajax({
type: "POST",
url: "/test/",
data: {
"imgfile": img,
},
processData: false,
contentType: false,
success: function(data){
console.log("success");
console.log(data);
},
failure: function(data){
console.log("failure");
console.log(data);
},
});
}
</script>
Djangoのビューが
@csrf_exempt
def testimg(request):
print "the request",request.POST
data = {"data": "ok"}
return JsonResponse(data)
あるprint文は
the request <QueryDict: {}>
私が間違って何をやっているを与えますか?
はい私は応答は同じです。 –