Fixed #19610 - Added enctype note to forms topics doc.

Thanks will@ for the suggestion.
This commit is contained in:
Tim Graham 2013-01-23 04:42:34 -05:00
parent b44a5d1924
commit 0de2645c00
2 changed files with 10 additions and 0 deletions

View File

@ -716,6 +716,8 @@ form data *and* file data::
Testing for multipart forms Testing for multipart forms
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. method:: Form.is_multipart
If you're writing reusable views or templates, you may not know ahead of time If you're writing reusable views or templates, you may not know ahead of time
whether your form is a multipart form or not. The ``is_multipart()`` method whether your form is a multipart form or not. The ``is_multipart()`` method
tells you whether the form requires multipart encoding for submission:: tells you whether the form requires multipart encoding for submission::

View File

@ -197,6 +197,14 @@ context variable ``form``. Here's a simple example template::
The form only outputs its own fields; it is up to you to provide the surrounding The form only outputs its own fields; it is up to you to provide the surrounding
``<form>`` tags and the submit button. ``<form>`` tags and the submit button.
If your form includes uploaded files, be sure to include
``enctype="multipart/form-data"`` in the ``form`` element. If you wish to write
a generic template that will work whether or not the form has files, you can
use the :meth:`~django.forms.Form.is_multipart` attribute on the form::
<form action="/contact/" method="post"
{% if form.is_multipart %}enctype="multipart/form-data"{% endif %}>
.. admonition:: Forms and Cross Site Request Forgery protection .. admonition:: Forms and Cross Site Request Forgery protection
Django ships with an easy-to-use :doc:`protection against Cross Site Request Django ships with an easy-to-use :doc:`protection against Cross Site Request