[Answer]-File Uploading Using Django

1๐Ÿ‘

โœ…

If there is an exception, you are not returning an HttpResponse object. Hence the error.

use form.is_valid() to see if the form is valid.
Something like this:

if request.method == 'POST':
    form = User_image_form(request.POST, request.FILES)
    if form.is_valid():
        usr_img = User_image(imgfile = form.cleaned_data['imgfile'])
        usr_img.user = user
        usr_img.save()
        return HttpResponse("yees the first upload is right !! :X")
    else:
        print form.errors #for debugging purposes only. 

    return HttpResponse("Noooooo!!!")
๐Ÿ‘คkarthikr

Leave a comment