diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-15 10:12:05 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-15 10:12:05 +0000 |
| commit | f0cd172cd0bccc519a6ecdf41b6a10b46ccffbcf (patch) | |
| tree | 062ffc271ea2f0c1e308f5e1245129efff856dba /docs/newforms.txt | |
| parent | 32ed883861ecded14e51dd8b72d097bc37572c6c (diff) | |
Fixed #5387 -- Added is_multipart method to forms. Original patch from Petr Marhhoun. Tests and documentation from Murkt.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6273 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/newforms.txt')
| -rw-r--r-- | docs/newforms.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/newforms.txt b/docs/newforms.txt index e9e98944a0..ba0247314b 100644 --- a/docs/newforms.txt +++ b/docs/newforms.txt @@ -776,6 +776,27 @@ form data *and* file data:: # Unbound form with a image field >>> f = ContactFormWithMugshot() +Testing for multipart forms +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you're writing some reusable views or templates, you may not know ahead of +time whether your form is a multipart form or not. The ``is_multipart()`` +method tells you if the form requires multipart encoding for submission:: + + >>> f = ContactFormWithMugshot() + >>> f.is_multipart() + True + +In a template, this sort of code could be useful:: + + {% if form.is_multipart %} + <form enctype="multipart/form-data" method="post" action="/foo/"> + {% else %} + <form method="post" action="/foo/"> + {% endif %} + {% form %} + </form> + Subclassing forms ----------------- |
