1👍
The error says that your view is not returning any HttpResponse
. There is one case that it’s possible –
def user_profile(request):
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid() and form.is_multipart():
new_user = save_file(request.FILES['image'])
return HttpResponse(new_user)
# ------^
# There is not else check. It's possible that the if condition is False.
# In that case your view is returning nothing.
else:
form = ImageForm()
return render_to_response('user_profile.html', { 'form': form })
0👍
Regarding that error, the problem is in your view: if your form is invalid, you are not returning a response to the client:
def user_profile(request):
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
new_user = save_file(request.FILES['image'])
return HttpResponse(new_user)
else:
form = ImageForm()
# *** Unindented
return render_to_response('user_profile.html', { 'form': form })
also (I don’t have much experience with file uploads) but I don’t think you need the is_multipart
check – it may be causing your form to appear invalid.
- [Answer]-Getting values from Django model
- [Answer]-Form-View Mapping Issue in Django
- [Answer]-Hashing Django password in a simple login form
- [Answer]-Trouble with django upload_to callable
Source:stackexchange.com