Edited docs/newforms.txt changes from [6273]
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6288 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7c27f3e7ba
commit
951ecbf7e6
|
@ -779,20 +779,20 @@ form data *and* file data::
|
||||||
Testing for multipart forms
|
Testing for multipart forms
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If you're writing some reusable views or templates, you may not know ahead of
|
If you're writing reusable views or templates, you may not know ahead of time
|
||||||
time whether your form is a multipart form or not. The ``is_multipart()``
|
whether your form is a multipart form or not. The ``is_multipart()`` method
|
||||||
method tells you if the form requires multipart encoding for submission::
|
tells you whether the form requires multipart encoding for submission::
|
||||||
|
|
||||||
>>> f = ContactFormWithMugshot()
|
>>> f = ContactFormWithMugshot()
|
||||||
>>> f.is_multipart()
|
>>> f.is_multipart()
|
||||||
True
|
True
|
||||||
|
|
||||||
In a template, this sort of code could be useful::
|
Here's an example of how you might use this in a template::
|
||||||
|
|
||||||
{% if form.is_multipart %}
|
{% if form.is_multipart %}
|
||||||
<form enctype="multipart/form-data" method="post" action="/foo/">
|
<form enctype="multipart/form-data" method="post" action="/foo/">
|
||||||
{% else %}
|
{% else %}
|
||||||
<form method="post" action="/foo/">
|
<form method="post" action="/foo/">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% form %}
|
{% form %}
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue