[英]How to port /{controller}/{action}/{id} routes in Pylons to Pyramid
[英]How to validate the form in pylons in the same controller action that initially rendered it?
我有以下控制器:
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'],
)
第一个动作用于初始表单呈现,第二个动作是在提交表单时。 是否可以合并它们并仅使用if request.POST =='POST'来检查表单是否已提交?
我尝试了一下,然后将@validate装饰器移动到form动作,但是它给了我WSOD,并且服务器停止提供服务:
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')
有没有办法执行单个操作并仍然使用验证装饰器?
愚蠢的我,这很简单。 这是我的代码:
class FormtestController(BaseController):
@validate(schema=EmailForm(state=c), form='form', post_only=True,
on_get=False,
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.