1👍
✅
The problem here is that your view must return some kind of Django Response object. Given that you’re using AJAX here, I’m guessing you’d want to use the JSONResponse object:
from django.http import JSONResponse
def user_ajax_set_photo(request):
if request.method == 'POST':
form = FileUploadForm(data=request.POST, files=request.FILES)
if form.is_valid():
print 'valid form'
else:
print 'invalid form'
print form.errors
return JSONResponse([True], safe=False)
Note that in JSON you can’t just have a floating Boolean value, so I wrapped that in an array. By default, when you pass a non-dict object into JSONResponse, you have to also pass safe=False
.
Source:stackexchange.com