Django: after form.is_valid check, cleaned_data is missing the image field

I have a form, with a bunch of fields, and then I have a:


The problem si that after the form.is_valid() check,


for example DOES return the actual name, however,


DOES NOT return anynthing.

In the print(request.POST) output, i get

u'profile_image': [u'02 Portfolio Page.jpg']

but in the print(form.cleaned_data) i get:

 'profile_image': None

Why is the file lost at the is_valid check? What should I do?


class NewChickForm(forms.Form):
first_name = forms.CharField()
last_name = forms.CharField()
def do_save(self):
    u = Subject(
        first_name = self.cleaned_data.get('first_name'),
        last_name = self.cleaned_data.get('last_name'),
        profile_image = self.cleaned_data.get('profile_image'),
    return u


s = Subject()
form = NewChickForm(request.POST) # 1)do i add here `request.FILES` ?
if form.is_valid():
    s = form.do_save()
            # 2) s.profile_image = form.cleaned_data.get('profile_image')?

Even if i do #1) and #2), i still get NONE


Make sure you've used the correct enctype on your HTML form:

<form enctype="multipart/form-data" method="post" action="/foo/">

Also, make sure you bind request.FILES when you construct the form object.

# Bound form with an image field, data from the request
>>> f = ContactFormWithMugshot(request.POST, request.FILES)

Binding uploaded files to a form

Edit: File Uploads

Need Your Help

Accessing parent objects while using a javascript module pattern variant

javascript class object design-patterns parent

Hi I'm using this module pattern variant and I'm looking for the best way to get access to a parent object. I realise there is no way to know what parents an object has so I want to include some co...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.