Uploading image files Uploading image files django django

Uploading image files


You don't seem to be binding the file data to the form.

profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.profile) 


Why not use the django-avatar project (I'm assuming you are thinking of adding user avatars to your project, based on the example)?

They have a pretty neat solution with an extra tag that resizes the image before displaying it first time. You store the original image and define the image sizes that you wish to accept on the website and the rest is done automagically for you.


This is just a matter of following the docs.

You are not using the correct form initialization in your post. In particular you are missing request.FILES parameter:

 form = ProfileForm(request.POST, request.FILES)

after the above the uploaded file can be retrieved from the FILES array:

 photo_file = request.FILES['photo']