使用Python + Pylons处理错误 [英] Error handling with Python + Pylons

查看:148
本文介绍了使用Python + Pylons处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Python + Pylons处理错误的正确方法是什么?

What is the proper way to handle errors with Python + Pylons?

说一个用户通过一个表单设置密码,当通过该表单传递给模型类时控制器引起错误,因为它太短。应该如何处理这个错误,以便在网页上显示一条错误消息,而不是整个脚本终止到错误页面?

Say a user sets a password via a form that, when passed to a model class via the controller, throws an error because it's too short. How should that error be handled so that an error message gets displayed on the web page rather than the entire script terminating to an error page?

如果有任何错误处理控制器本身?

Should there be any error handling in the controller itself?

我希望我清楚地说明自己。

I hope I am explaining myself clearly.

谢谢。

推荐答案

你用什么来验证你的表单?我正在使用 formchemy 。它使用内置和自定义验证器验证输入数据,并为列表提供其找到的错误。然后,您可以在模板中以任何方式显示该列表。

What are you using to validate your forms? I'm using formalchemy. It validates the input data using built-in and custom validators, and feeds a list with the errors it finds. You can then display that list in any way you want in your template.

文档这里

这篇关于使用Python + Pylons处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆