Answer the question
In order to leave comments, you need to log in
How to send file(s) using AJAX with Jquery and get them in Django view?
//так я получаю текст инпут
var text = $('#form-new-task-z-r-text').val();
//тут мне надо получить инпут с файлами
//<input type="file" name="file" multiple="" required="" id="file_record">
//var my_file = ...
$.ajax({
type: 'POST',
url: 'add_new_rec/'+prot_id+'/'+id_q+'/',
data: {csrfmiddlewaretoken: getCookie('csrftoken'), 'r_text':text, 'file':my_file}, //'file' - это мои файлы
success: function(data) {
}
});
def add_new_rec(request,id_prot,id_q):
text = request.POST.get("r_text")
#Как принять мой(и) file ?
Answer the question
In order to leave comments, you need to log in
jQuery.ajax({
type: 'POST',
url: 'add_new_rec/'+prot_id+'/'+id_q+'/',
async: true,
cache: false,
processData: false,
contentType: false,
enctype: 'multipart/form-data',
data: {csrfmiddlewaretoken: getCookie('csrftoken'), 'r_text':text, 'file':my_file},
success: function (data) {
}
});
model.field = request.FILES['my_file']
model.save()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question