The previous step was the smallest possible step into a Colander schema and Deform form based on that schema. Let's take another very small step, but show processing the form.
- More validation
- Handle form submission
- Process the submitted form by detecting a POST
- Show the 3-way code path: GET vs. valid POST vs. invalid POST
- Display the validated values
- $ cd ../../forms_schema; mkdir step02; cd step02
- (Unchanged) Copy the following into step02/application.py:
- Copy the following into step02/views.py:
- Copy the following into step02/templates/site_view.pt:
- Copy the following into step02/tests.py:
- $ nosetests should report running 2 tests.
- $ python application.py
- Open http://127.0.0.1:8080/ in your browser.
- If the form was successfully submitted, display a status message at the top of the screen.
In this step we see the explicit branching in a self-posting form. This is important: it's useful to have a common pattern to see which code path goes where, especially on a large project with lots of forms.
In many cases, this self-posting form isn't going to return itself on success. Instead, it will redirect using pyramid.httpexceptions.HTTPFound to the newly-created resource.
- Impact of a form library on test writing