From f0cd172cd0bccc519a6ecdf41b6a10b46ccffbcf Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 15 Sep 2007 10:12:05 +0000 Subject: 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 --- docs/newforms.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'docs/newforms.txt') 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 %} +
+ {% else %} + + {% endif %} + {% form %} +
+ Subclassing forms ----------------- -- cgit v1.3