1FAQ 2=== 3 4This contains the most commonly asked questions about WTForms. The most current 5version of this document can always be found on the `WTForms Website`_. 6 7.. _WTForms Website: http://wtforms.simplecodes.com 8 9 10Does WTForms work with [library here]? 11-------------------------------------- 12 13The answer is most likely **yes**. WTForms tries to provide as usable an API as 14possible. We've listed here some of the known libraries to work with WTForms, 15but if it's not listed, it doesn't mean it won't work. 16 17* **Request/Form Input** 18 19 * Django 20 * Webob (Includes Pylons, Google App Engine, Turbogears) 21 * Werkzeug (Includes Flask, Tipfy) 22 * any other cgi.FieldStorage-type multidict 23 24* **Templating Engines** 25 26 * Jinja2 27 * Mako 28 * Django Templates (To get the full power of WTForms in your templates, you 29 will need to use the Django :mod:`extension <wtforms.ext.django>`.) 30 * Genshi 31 32* **Database Objects** 33 34 * Pretty much any ORM or object-DB should work, as long as data objects allow 35 attribute access to their members. 36 37 Special support is there for SQLAlchemy, Google App Engine, and Django 38 collections via :mod:`extensions <wtforms.ext>`. 39 40 41Does WTForms support unicode? 42----------------------------- 43 44Simple answer: Yes. 45 46Longer answer: WTForms uses unicode strings throughout the source code, and 47assumes that form input has already been coerced to unicode by your framework 48(Most frameworks already do this.) WTForms fields render to unicode strings by 49default, and therefore as long as your templating engine can work with that, 50you should have no unicode issues. 51 52 53What versions of Python are supported? 54-------------------------------------- 55 56WTForms supports Python 2.6-2.7 and 3.2+ with a single codebase. Without 2to3 tool. 57 58 59How can I contribute to WTForms? 60-------------------------------- 61 62WTForms is not that scary. Really. We try to keep it as succint and readable as 63possible. If you feel like you have something to contribute to WTForms, let us 64know on the `mailing list`_. For bugs and feature requests, you can file a 65ticket on the `project page`_. 66 67.. _mailing list: http://groups.google.com/group/wtforms 68.. _project page: http://github.com/wtforms/wtforms 69 70 71How do I mark in a template when a field is required? 72----------------------------------------------------- 73 74Some validators (notably Required and Optional) set flags on the fields' 75:attr:`~wtforms.fields.Field.flags` object. To use this in a template, you can 76do something like: 77 78.. code-block:: html+jinja 79 80 {% for field in form %} 81 {{ field }} 82 {% if field.flags.required %}*{% endif %}{{ field.label }} 83 {% endfor %} 84 85 86Does WTForms handle file uploads? 87--------------------------------- 88 89Currently, it does not. This is because WTForms strives to be 90framework-agnostic, and every web framework handles file uploads somewhat 91differently. WTForms has a :class:`~wtforms.fields.FileField` which will let 92you render a file input widget, but the rest is up to you. An example use in a 93django-ish framework:: 94 95 class MyForm(Form): 96 image = FileField() 97 98 def my_view(request): 99 form = MyForm(request.POST) 100 file_wrapper = request.FILES[form.image.name] 101 # Do things with your file wrapper now 102 103Using ``form.image.name`` is an easy way to know what input name was generated 104for your file input, even if the form is prefixed. 105 106 107Why does blank input not go back to the default value? 108------------------------------------------------------ 109 110A key design decision of WTForms was that form data -always- takes precedence 111when there's a form submission. That is, if a field exists on a form, and a 112form was posted, but that field's value was missing, it will not revert to a 113default, but instead store an empty value (and in some cases cause a validation 114error.) 115 116This is for a number of reasons: 117 1181. Security. If a form reverted to defaults on missing data, then an evil user 119 could potentially cause problems by submitting a hand-coded form with key 120 missing fields. 121 1222. Bug-finding. If you omitted a field in your template, it might fall through 123 to the default and you'd possibly miss it. 124 1253. Consistency. 126 127See the following mailing list posts for more discussion on the topic: 128 - http://groups.google.com/group/wtforms/browse_frm/thread/6755a45a13878e9 129 - http://groups.google.com/group/wtforms/msg/fa409c8c89b6f62d 130 131 132How do I... [convoluted combination of libraries] 133------------------------------------------------- 134 135You'll probably want to check out our 136:ref:`Solving Specific Problems <specific_problems>` doc. 137