Код: Выделить всё
# html
{% csrf_token %} # django security
Код: Выделить всё
# javascript
$(document).on('submit', '#Form', function(e){
e.preventDefault();
var form_data = new FormData();
form_data.append('file', $('#image_file').get(0).files);
$.ajax({
type:'POST',
url:'my_url',
processData: false,
contentType: false,
data:{
logo:form_data,
csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val(), # django security
},
});
});
Код: Выделить всё
# views.py (server side)
def myFunction(request):
if request.method == 'POST':
image_file = request.FILES
...
...
Я что-то делаю неправильно?
Подробнее здесь: https://stackoverflow.com/questions/447 ... ax-on-post
Мобильная версия