mirror of
https://github.com/django/django.git
synced 2025-10-10 02:22:22 +00:00
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
This commit is contained in:
parent
32ed883861
commit
f0cd172cd0
5 changed files with 53 additions and 0 deletions
|
@ -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
|
||||
-----------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue