~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to docs/topics/forms/index.txt

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
example, we passed our ``ContactForm`` instance to the template using the
173
173
context variable ``form``. Here's a simple example template::
174
174
 
175
 
    <form action="/contact/" method="POST">
 
175
    <form action="/contact/" method="post">
176
176
    {{ form.as_p }}
177
177
    <input type="submit" value="Submit" />
178
178
    </form>
183
183
``form.as_p`` will output the form with each form field and accompanying label
184
184
wrapped in a paragraph. Here's the output for our example template::
185
185
 
186
 
   <form action="/contact/" method="POST">
 
186
   <form action="/contact/" method="post">
187
187
   <p><label for="id_subject">Subject:</label>
188
188
       <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
189
189
   <p><label for="id_message">Message:</label>
211
211
the way a form is presented using the Django template language. Extending the
212
212
above example::
213
213
 
214
 
    <form action="/contact/" method="POST">
 
214
    <form action="/contact/" method="post">
215
215
        <div class="fieldWrapper">
216
216
            {{ form.subject.errors }}
217
217
            <label for="id_subject">E-mail subject:</label>
263
263
duplicate code by looping through each field in turn using a ``{% for %}``
264
264
loop::
265
265
 
266
 
    <form action="/contact/" method="POST">
 
266
    <form action="/contact/" method="post">
267
267
        {% for field in form %}
268
268
            <div class="fieldWrapper">
269
269
                {{ field.errors }}
322
322
``visible_fields()``. Here's a modification of an earlier example that uses
323
323
these two methods::
324
324
 
325
 
    <form action="/contact/" method="POST">
 
325
    <form action="/contact/" method="post">
326
326
        {% for field in form.visible_fields %}
327
327
            <div class="fieldWrapper">
328
328
 
356
356
can reduce duplication by saving the form's loop in a standalone template and
357
357
using the :ttag:`include` tag to reuse it in other templates::
358
358
 
359
 
    <form action="/contact/" method="POST">
 
359
    <form action="/contact/" method="post">
360
360
        {% include "form_snippet.html" %}
361
361
        <p><input type="submit" value="Send message" /></p>
362
362
    </form>
373
373
If the form object passed to a template has a different name within the
374
374
context, you can alias it using the :ttag:`with` tag::
375
375
 
376
 
    <form action="/comments/add/" method="POST">
 
376
    <form action="/comments/add/" method="post">
377
377
        {% with comment_form as form %}
378
378
            {% include "form_snippet.html" %}
379
379
        {% endwith %}