У меня есть простая форма в index.html
:request.FILES пуст, когда запрос загрузки отправить Аякс файла на сервер
<div id="Competence-form">
<form id="competence" method="post" action="/" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" id="Picture-text" name="comp-pic" />
<input type="button" name="comp-defaultButton" value="Default" />
</form>
</div>
и вот мой запрос Ajax в index.js
:
$("#Competence-form").submit(function(event){
$(".ajaxLogoBoard").show();
//prevent normal submit when submit button click because check something ...
event.preventDefault();
//getting values
var picture = $("#Picture-text").val();
var data ={
picture:picture,
};
//send AJAX
$.ajax({
url: '/ajax/check',
data: data,
dataType: 'json',
success:function(result){
// do something
}
В серверном I хотите использовать request.FILES
, но этот словарь пуст:
def competenceCheck(request):
# ... some code to initialize upload
# ...
picture = request.REQUEST['picture'] # this will return the path
print request.FILES # but this is empty => <MultiValueDict: {}>
# ... some code after upload
# ...
где я ошибаюсь?
Я исправляю это. – mojibuntu