Skip to content

Commit 0de2645

Browse files
committed
Fixed django#19610 - Added enctype note to forms topics doc.
Thanks will@ for the suggestion.
1 parent b44a5d1 commit 0de2645

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/ref/forms/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ form data *and* file data::
716716
Testing for multipart forms
717717
~~~~~~~~~~~~~~~~~~~~~~~~~~~
718718

719+
.. method:: Form.is_multipart
720+
719721
If you're writing reusable views or templates, you may not know ahead of time
720722
whether your form is a multipart form or not. The ``is_multipart()`` method
721723
tells you whether the form requires multipart encoding for submission::

docs/topics/forms/index.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ context variable ``form``. Here's a simple example template::
197197
The form only outputs its own fields; it is up to you to provide the surrounding
198198
``<form>`` tags and the submit button.
199199

200+
If your form includes uploaded files, be sure to include
201+
``enctype="multipart/form-data"`` in the ``form`` element. If you wish to write
202+
a generic template that will work whether or not the form has files, you can
203+
use the :meth:`~django.forms.Form.is_multipart` attribute on the form::
204+
205+
<form action="/contact/" method="post"
206+
{% if form.is_multipart %}enctype="multipart/form-data"{% endif %}>
207+
200208
.. admonition:: Forms and Cross Site Request Forgery protection
201209

202210
Django ships with an easy-to-use :doc:`protection against Cross Site Request

0 commit comments

Comments
 (0)