Django

Code

root/django/branches/multiple-db-support/docs/newforms.txt

Revision 4189, 2.6 kB (checked in by jpellerin, 2 years ago)

[multi-db] Merged trunk to [4188]. Some tests still failing.

Line 
1 ====================
2 The newforms library
3 ====================
4
5 ``django.newforms`` is a new replacement for ``django.forms``, the old Django
6 form/manipulator/validation framework. This document explains how to use this
7 new form library.
8
9 Migration plan
10 ==============
11
12 ``django.newforms`` currently is only available in the Django development version
13 -- i.e., it's not available in the Django 0.95 release. For the next Django
14 release, our plan is to do the following:
15
16     * Move the current ``django.forms`` to ``django.oldforms``. This will allow
17       for an eased migration of form code. You'll just have to change your
18       import statements::
19
20           from django import forms             # old
21           from django import oldforms as forms # new
22
23     * Move the current ``django.newforms`` to ``django.forms``.
24
25     * We will remove ``django.oldforms`` in the release *after* the next Django
26       release -- the release that comes after the release in which we're
27       creating ``django.oldforms``.
28
29 With this in mind, we recommend you use the following import statement when
30 using ``django.newforms``::
31
32     from django import newforms as forms
33
34 This way, your code can refer to the ``forms`` module, and when
35 ``django.newforms`` is renamed to ``django.forms``, you'll only have to change
36 your ``import`` statements.
37
38 If you prefer "``import *``" syntax, you can do the following::
39
40     from django.newforms import *
41
42 This will import all fields, widgets, form classes and other various utilities
43 into your local namespace. Some people find this convenient; others find it
44 too messy. The choice is yours.
45
46 Overview
47 ========
48
49 As the ``django.forms`` system before it, ``django.newforms`` is intended to
50 handle HTML form display, validation and redisplay. It's what you use if you
51 want to perform server-side validation for an HTML form.
52
53 The library deals with these concepts:
54
55     * **Widget** -- A class that corresponds to an HTML form widget, e.g.
56       ``<input type="text">`` or ``<textarea>``. This handles rendering of the
57       widget as HTML.
58
59     * **Field** -- A class that is responsible for doing validation, e.g.
60       an ``EmailField`` that makes sure its data is a valid e-mail address.
61
62     * **Form** -- A collection of fields that knows how to validate itself and
63       display itself as HTML.
64
65
66
67 Using forms with templates
68 ==========================
69
70 Using forms in views
71 ====================
72
73 More coming soon
74 ================
75
76 That's all the documentation for now. For more, see the file
77 http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/tests.py
78 -- the unit tests for ``django.newforms``. This can give you a good idea of
79 what's possible.
Note: See TracBrowser for help on using the browser.