FormEncode、pylons 和 mako 示例

发布于 2024-07-29 19:54:46 字数 350 浏览 6 评论 0原文

我正在使用 mako 在 pylons 中工作,我想使用 FormEncode 为我的应用程序的几个部分创建表单和验证。 我似乎找不到整个过程的任何好的例子。 我的问题有两个:

技术

  • FancyValidators 和 Schemas - 它们的关系和语法
  • Pylons 控制器和 mako 模板 - 如何收集、处理和验证数据

风格

  • 控制器方法的最佳实践
  • 简化表单的重用(例如,更新与创建)

因此,如果您知道任何完整的示例,我们将不胜感激。 我认为这将是一个常见的组合,有更多的示例/教程。

I'm working in pylons with mako, and I'd like to create forms and validations with FormEncode for several parts of my application. I can't seem to find any good examples of the whole process. My question is twofold:

Technical

  • FancyValidators and Schemas - Their relationship and syntax
  • Pylons controllers and mako templates - how to collect, handle, and validate the data

Stylistic

  • Best practices for controller methods
  • Easing the reuse of forms (for update vs create, for example)

So if you know of any complete examples, it would be much appreciated. I would think this would be a common combination with more examples/tutorials out there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2024-08-05 19:54:46

我不知道你是否读过 pylons 书,但我发现 第 6 章 在表格方面非常彻底。

就最佳实践而言,我不太确定您在寻找什么。 控制器方法映射到 url 并需要返回类似字符串的对象。 如何实现这一点很大程度上取决于应用程序的具体情况,您可以自由选择如何构建应用程序。

对于表单重用,我不知道它是否被认为是最佳实践,但我发现 tw.forms 对此非常有用(以及用于一般 html 片段重用的 toscawidgets)。 如果您预计必须重用表单中的字段,那么字段集可能会取得一些成功。

如果您正在寻找完整的示例,我会认为turbogears2是一个很好的资源。 它建立在塔架之上,因此有关 tg2 的任何信息同样适用于塔架。

你还可以查看 reddit 源代码

最后,有人会推荐 django。 :)

I don't know if you've gone through the pylons book, but I found chapter 6 to be very thorough in regards to forms.

As far as best practices go, I'm not exactly sure what you are looking for. A controller method maps to a url and needs to return a string-like object. How you arrive at that is largely application specific and you are free to choose how you structure the application.

For form reuse, I don't know if it would be considered a best practice but tw.forms I find pretty useful for just that (and toscawidgets for general html snippet reuse). If you anticipate having to reuse fields in forms, you may have some success with fieldsets.

If you are looking for complete examples, I would consider turbogears2 a good resource. It's built on top of pylons so any information on tg2 is equally applicable to pylons.

You can also look at the reddit source code

And finally, someone will suggest django. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文