Rendering forms and fields ========================== Most of the time you'll be using morf to display, validate and process web forms. The class :class:`~morf.htmlform.HTMLForm` provides shortcuts for this. Most of the time it's convenient to create forms by subclassing this. Basic rendering --------------- Forms, by default, do not know anything about HTML. For that you need a :class:`morf.render.FormRenderer` object. There are various flavours of FormRenderer that render in different HTML markup styles. The easiest way to get hold of a :class:`~morf.render.FormRenderer` object is to use one of the ``.as_*`` methods on :class:`~morf.htmlform.HTMLForm`: .. testcode :: from morf import HTMLForm, fields class MyForm(HTMLForm): email = fields.Str() name = fields.Str() form = MyForm() print(form.as_p()) Which outputs the rendered HTML: .. testoutput ::
... Customizing rendering templates ------------------------------- You can customize the HTML generated by calling :meth:`~morf.htmlform.HTMLForm.renderer`: .. testcode:: from markupsafe import Markup renderer = form.renderer( form_template='