我尝试在不发送所有表单的情况下从<input type="file" id="file" name="file" accept="image/*" multiple>
发送图像。我发现很多帖子解释了这一点,所以我这样做了
urls.py
url(r'^images/', 'app.views.images', name='images'),
view.py
def images(request):
if request.method == 'POST':
print('hello')
jquery
$("#file").change(function (){
try{
var formdata = new FormData();
var files = $('#file')[0].files;
formdata.append('file',files);
jQuery.ajax({
url: "images/",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (result) {
// if all is well
// play the audio file
}
});
}
catch(err){
alert(err.message);
}
});
但是这给了我一个"POST /images/ HTTP/1.1" 403
错误
我做了不同的测试,我认为错误是data: formdata
部分
https://stackoverflow.com/questions/55695849
复制相似问题