Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1653 -- added some documentation for FileFields/ImageFields. T…

…hanks, Asmodai.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3466 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 09912cce7068c27c21a6bbc4077d76faf1a698d1 1 parent 847b1ed
Jacob Kaplan-Moss authored

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. 30  docs/forms.txt
30  docs/forms.txt
@@ -404,6 +404,36 @@ Here's a simple function that might drive the above form::
404 404
             errors = new_data = {}
405 405
         form = forms.FormWrapper(manipulator, new_data, errors)
406 406
         return render_to_response('contact_form.html', {'form': form})
  407
+        
  408
+``FileField``s and ``ImageField``s
  409
+==================================
  410
+
  411
+Dealing with for ``FileField`` and ``ImageField`` is a little more
  412
+complicated.
  413
+
  414
+First, you'll need to make sure that your ``<form>`` element correctly defines
  415
+the ``enctype`` in order to upload files::
  416
+
  417
+  <form enctype="multipart/form-data" method="POST" action=".">
  418
+
  419
+Next, you'll need to treat the field in the template slightly differently.
  420
+Given a field in the model::
  421
+
  422
+   photo = model.ImageField('/path/to/upload/location')
  423
+
  424
+You need to actually display two formfields in the template:
  425
+
  426
+   <p><label for="id_photo">Photo:</label> {{ form.photo }}{{ form.photo_file }}</p>
  427
+
  428
+The first bit (``{{ form.photo }}``) displays the currently-selected file,
  429
+while the second (``{{ form.photo_file }}``) actually contains the file upload
  430
+form field. Thus, at the validation layer you need to check the ``photo_file``
  431
+key.
  432
+
  433
+Finally, in the view, make sure to call ``new_data.update(request.FILES)``::
  434
+
  435
+   new_data = request.POST.copy()
  436
+   new_data.update(request.FILES)
407 437
 
408 438
 Validators
409 439
 ==========

0 notes on commit 09912cc

Please sign in to comment.
Something went wrong with that request. Please try again.