class documentation
A Form
is a collection of fields attached to a function.
Class Method | renderer |
A form parameter that can render a form declared as a number of fields on another route. |
Static Method | on |
Register a function to be run in the event of a validation failure for the input to a particular form handler. |
Method | populate |
Extract the values present in this request and populate a FieldValues object. |
Instance Variable | fields |
Form fields |
@classmethod
def rendererFor(cls, decoratedFunction, action, method='POST', enctype=RenderableForm.ENCTYPE_FORM_DATA, encoding='utf-8'): (source)
def rendererFor(cls, decoratedFunction, action, method='POST', enctype=RenderableForm.ENCTYPE_FORM_DATA, encoding='utf-8'): (source)
A form parameter that can render a form declared as a number of fields on another route.
Use like so:
class MyFormApp: router = Klein() requirer = Requirer() @requirer.require( router.route("/handle-form", methods=["POST"]), name=Field.text(), value=Field.integer(), ) def formRoute(self, name, value): ... @requirer.require( router.route("/show-form", methods=["GET"]), form=Form.rendererFor(formRoute) ) def showForm(self, form): return form
As a RenderableForm
provides IRenderable
, you may return the parameter directly
Parameters | |
decorated_requirerFunctionWithForm | Undocumented |
action:str | Undocumented |
method:str | Undocumented |
enctype:str | Undocumented |
encoding:str | Undocumented |
Returns | |
RenderableFormParam | Undocumented |
Register a function to be run in the event of a validation failure for the input to a particular form handler.
Generally used like so:
requirer = Requirer(...) @requirer.prerequisite([ISession]) def procureSession(request): return SessionProcurer(...).procureSession(request) router = Klein() @requirer.require(router.route("/", methods=['POST']), someField=Field.text()) def formHandler(someField): ... # Handle input validation failures for handleForm @Form.onValidationFailureFor(formHandler) def handleValidationFailures(request, fieldValues): return "Your inputs didn't validate."
Parameters | |
handler:_requirerFunctionWithForm | The form handler - i.e. function decorated by Form.handler - for which the decorated function will handle validation failures. |
Returns | |
Callable[ | a decorator that decorates a function with the signature (request, form) -> thing klein can render. |
See Also | |
defaultValidationFailureHandler for a more detailed description of the decorated function's expected signature. The additional parameter it is passed is a FieldValues instance. |
from
klein._form.IForm
Extract the values present in this request and populate a FieldValues
object.
Parameters | |
injectionComponentized | Undocumented |
instance:Any | Undocumented |
request:IRequest | Undocumented |
Returns | |
Generator[ | Undocumented |