Form.is_multipart()
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 tells you whether the form requires multipart encoding for submission:
1 2 3 | >>> f = ContactFormWithMugshot() >>> f.is_multipart() True |
Here’s an example of how you might use this in a template:
1 2 3 4 5 6 7 | { % if form.is_multipart % } <form enctype = "multipart/form-data" method = "post" action = "/foo/" > { % else % } <form method = "post" action = "/foo/" > { % endif % } {{ form }} < / form> |
Please login to continue.