I have the following controller:
class FormtestController(BaseController):
def form(self):
return ender('/simpleform.html')
@validate(schema=EmailForm(state=c), form='form', post_only=False, on_get=True,
auto_error_formatter=custom_formatter)
def submit(self):
return 'Your email is: %s and the date selected was %r.' % (
self.form_result['email'],
self.form_result['date'],
)
The first action is for initial form rendering and the second one is when the form is submitted. Is it possible to merge them and just use an if request.POST == 'POST' to check if the form has been submitted?
I tried it and move the @validate decorator to the form action but it gives me a WSOD and the server stops serving:
class FormtestController(BaseController):
@validate(schema=EmailForm(state=c), form='form', post_only=False, on_get=True,
auto_error_formatter=custom_formatter)
def form(self):
if request.method == 'POST':
return 'Your email is: %s and the date selected was %r.' % (
self.form_result['email'],
self.form_result['date'],
)
return render('/simpleform.html')
Is there a way to have a single action and still use the validate decorator?