File: meta.rst

package info (click to toggle)
wtforms 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 964 kB
  • ctags: 1,360
  • sloc: python: 5,163; makefile: 73
file content (73 lines) | stat: -rw-r--r-- 2,190 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class Meta
==========

.. module:: wtforms.meta

the `class Meta` paradigm allows WTForms features to be customized, and even
new behaviors to be introduced. It also supplies a place where configuration
for any complementary modules can be done.

Typical usage looks something like::

    class MyForm(Form):
        class Meta:
            csrf = True
            locales = ('en_US', 'en')

        name = TextField(...)
        # and so on...

For the majority of users, using a class Meta is mostly going to be done for
customizing options used by the default behaviors, however for completeness
the entire API of the `Meta` interface is shown here.

.. autoclass:: DefaultMeta
    
    **Configuration**
    
    .. autoattribute:: csrf

        Setting ``csrf`` to `True` will enable CSRF for the form. The value can 
        also be overridden per-instance via instantiation-time customization
        (for example, if csrf needs to be turned off only in a special case)

        .. code-block:: python

            form = MyForm(request.form, meta={'csrf': False})

    .. autoattribute:: csrf_class

        If set, this is a class which is used to implement CSRF protection.
        Read the :doc:`CSRF Documentation <csrf>` to get more information on 
        how to use.

    .. autoattribute:: csrf_field_name

        The name of the automatically added CSRF token field.

    .. autoattribute:: locales

        Setting to a sequence of strings specifies the priority order
        of locales to try to find translations for built-in messages of 
        WTForms. If the value `False`, then strings are not translated 
        (the translations provider is a dummy provider)

    .. autoattribute:: cache_translations

        If `True` (the default) then cache translation objects. The default 
        cache is done at class-level so it's shared with all class Meta.

    **Advanced Customization**

    Usually, you do not need to override these methods, as they provide core
    behaviors of WTForms.

    .. automethod:: build_csrf

    .. automethod:: get_translations

    .. automethod:: bind_field

    .. automethod:: wrap_formdata

    .. automethod:: render_field