Hi. I write web-site at Django.
I want created object with images using jquery and ajax.
<form action="" class="edit_form new_event" enctype="multipart/form-data" method="GET">
{% csrf_token %}
{{ form.main_photo }}
{{ form.profile_photo }}
<button class="submit mgln" type='button'>Send</button>
</form>
<script>
$('.mgln').on('click', function(){
main_photo = $('input[name=main_photo]').val();
profile_photo = $('input[name=profile_photo]').val();
data = {
main_photo: main_photo,
profile_photo: profile_photo,
}
console.log(data)
$.ajax({
type: "GET",
url: "{% url 'identification_view' %}",
data: data,
success: function(result) {
alert('Ok.');
},
error: function(result) {
alert('Error');
}
})
})
</script>
def identification_view(request):
if request.method == 'POST':
form = IdentificationForm(request.POST, request.FILES)
if form.is_valid():
req_user = form.save(commit=False)
req_user.user = request.user
req_user.save()
return HttpResponse('image upload success')
else:
form = IdentificationForm()
return render(request, 'accounts/identification.html', {'form': form})
I get file with fake path… C:\fake/<name_of_image>