title: Upload image with Django CBV CreateView
body: <p>I am trying to create a user profile after registering a user. In this profile, I need to upload an image. But I keep getting a KeyError when validating the image.</p>
  
  <p>After several hours of googling and trying different solutions, I am now stuck. Can someone please show me what I am doing wrong? Thanks in advance.</p>
  
  <p>models.py</p>
  
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User,
                                  on_delete=models.CASCADE)
      slug = models.SlugField(default='',
                              editable=False)
      picture = models.ImageField('Profile picture',
                                  upload_to='profile_pics/%Y-%m-%d/',
                                  null=True,
                                  blank=True)
      bio = models.CharField("Short Bio", max_length=200, blank=True, null=True)
      email_verified = models.BooleanField("Email verified", default=False)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from .models import Profile
  from .forms import ProfileForm
  
  class CreateProfile(FormView):
      model = Profile
      template_name = 'profiles/profile_form.html'
      form_class = ProfileForm
      fields = ['picture', 'bio']
  
      def get_success_url(self):
          return reverse('profiles:detail', kwargs={'slug': self.slug})
  
  
      def form_valid(self, form):
          profile = form.save(commit=False)
          image = form.cleaned_data['image']
          obj.user = self.request.user
          profile.save()
  
          return HttpResponseRedirect(self.get_success_url())
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from .models import Profile
  
  
  class ProfileForm(forms.ModelForm):
      class Meta:
          model = Profile
          fields = ['picture', 'bio',]
  </code></pre>
  
  <p>Traceback:</p>
  
  <pre><code>File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
    42.             response = get_response(request)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
    187.                 response = self.process_exception_by_middleware(e, request)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
    185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/views/generic/base.py" in view
    68.             return self.dispatch(request, *args, **kwargs)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/views/generic/base.py" in dispatch
    88.         return handler(request, *args, **kwargs)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/lib/python3.5/site-packages/django/views/generic/edit.py" in post
    183.             return self.form_valid(form)
  
  File "/home/xxxxxxxxxx/xxxxxxxx/xxxxxxx/template/profiles/views.py" in form_valid
    28.         image = form.cleaned_data['image']
  
  Exception Type: KeyError at /profiles/create/
  Exception Value: 'image'
  </code></pre>