我想一次使用javascript和python上傳多個文件。每當我做ajax請求時,都會發生錯誤(403或禁止)。我不知道到底是什麼問題? 請幫我...使用jquery和python進行異步文件上傳
,這裏是我的index.html ..
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<input id="fileupload" type="file" name="files[]" data-url="/media/" multiple>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="/static/js/jquery.ui.widget.js"></script>
<script src="/static/js/jquery.iframe-transport.js"></script>
<script src="/static/js/jquery.fileupload.js"></script>
<script>
$(function() {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
</script>
<script>
$('#fileupload').fileupload({
/* ... */
progressall: function (e, data) {
var progress = parseInt(data.loaded/data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
});
</script>
</body>
</html>
,這裏是我的觀點...
def update_file(request):
print "view is called"
context = RequestContext(request)
context_dict = {}
if request.method== "POST":
image = request.POST.get('image')
request.user.userprofile.resume.delete()
request.user.userprofile.resume = image
request.user.userprofile.save()
return render_to_response('index.html', context_dict, context)
您是否在服務器上啓用了Django日誌記錄功能?通常你可以看到有關403發生的更多細節。或者,如果您在設置中設置了DEBUG = True,則可能會獲得有關該錯誤的更多詳細信息。 – Jacinda