title: Django file upload with UpdateView
body: <p>I tried a minimalistic django implementation of generic views to upload profile pictures.</p>
  
  <p>views.py</p>
  
  <pre><code>class UpdateProfile(UpdateView):
      form_class = UpdateUserProfileForm
      model = UserProfile
      success_url = reverse_lazy('show_profile')
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User)
      website = models.URLField(blank=True)
      picture = models.ImageField(upload_to='user/img/%Y-%m-%d/', blank=True)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class UpdateUserProfileForm(forms.ModelForm):
      class Meta:
          model = UserProfile
          fields = ['website','picture']
  </code></pre>
  
  <p>userprofile_form.html</p>
  
  <pre><code>&lt;form action="" enctype="multipart/form-data" method="post"&gt;{% csrf_token %}
      {{ form.as_p }}
      &lt;input type="submit" value="{% trans "Save" %}"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Everything works fine. Now error message. The website field will be updated properly, and a search button allows to choose a file for upload. However the file never appears in the system and the database field remains empty.</p>
  
  <p>Unfortunately the django documentation on file upload (<a href="https://docs.djangoproject.com/en/1.10/topics/http/file-uploads/" rel="noreferrer">https://docs.djangoproject.com/en/1.10/topics/http/file-uploads/</a>) does not include generic views, so I wonder if it is possible at all.</p>
  
  <p><strong>Update:</strong> Thanks to Alasdair's answer I updated my template so it works fine now as a minimalistic prototype for picture upload with generic views.</p>
  
  <p>To display the picture, instructions of the documentation (<a href="https://docs.djangoproject.com/en/1.10/howto/static-files/" rel="noreferrer">https://docs.djangoproject.com/en/1.10/howto/static-files/</a>) are quite helpful again.</p>
  
  <p>Also the media settings are necessary to upload the files to the media folder.</p>
  
  <p>settings.py</p>
  
  <pre><code>MEDIA_URL = '/media/'
  MEDIA_ROOT = 'absolute-path-to/media'
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.conf import settings
  from django.conf.urls.static import static
  urlpatterns = [
  ...
  ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p>template</p>
  
  <pre><code>{% if userprofile.picture.url|length &gt; 0 %}
      &lt;img src="{{ userprofile.picture.url }}" width="200px"&gt;
  {% else %}
      &lt;img src="{% static "/img/default_profile.jpg" %}" width="200px" /&gt;
  {% endif %}
  </code></pre>