我对可重用 Django 应用程序做错了什么?

发布于 2024-09-19 10:21:45 字数 536 浏览 5 评论 0原文

几乎总是当我尝试使用可重用的 django 应用程序时,我最终会做大量的集成工作和/或最终结果非常混乱。

一个常见的、更简单的情况是发送确认消息(使用 链接text框架)给用户,用于可重用应用程序中发生的事件。以 django-profiles 为例 - 为了显示“配置文件成功保存”消息,我通常会包装原始视图函数,查看它是否返回 HttpResponseRedirect 并显示消息(如果是)。然后返回原始响应。

我不喜欢的是它很丑(依赖于返回类型),而且我必须添加整个视图才能显示消息。

那么,

  • 我做错了什么?
  • 向用户显示确认消息不是习惯吗?
  • 对于可重用应用程序来说,接受可选的用户消息作为视图参数是否有意义?
  • 如果可重用应用程序使用更多信号来允许挂钩自定义功能,那不是很好吗?

Almost always when I try to use a re-usable django app, I end up doing a lot of integration work and/or the end result is really messy.

A common, simpler case is sending confirmation messages (with link text framework) to the user, for events that take place in the re-usable app. Take for example django-profiles - in order to show a "profile succesfully saved" message, I would typically wrap the original view function, see if it returns a HttpResponseRedirect and show the message if so. Then return the original response.

What I don't like in this is that it's ugly (relying on the return type) and I have to add a whole view just to show the message.

So,

  • what am I doing wrong?
  • Is it not customary to show confirmation messages to users?
  • Would it make sense for re-usable apps to also accept optional user messages as the view parameters?
  • Wouldn't it be nice if re-usable apps used signals a lot more to allow hooking custom functionality?

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

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

发布评论

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

评论(1

孤檠 2024-09-26 10:21:46

向用户显示确认消息不是惯例吗?

是的。

对于可重用应用程序来说,接受可选的用户消息作为视图参数是否有意义?

可能是的。

如果可重复使用的应用程序使用更多信号来允许挂钩自定义功能,那不是很好吗?

最肯定的是,是的。

我做错了什么?

您正在使用的应用程序不符合上述标准。这并不完全难以解决。您始终可以推出符合您上面设置的标准的自己的应用程序。或者,您可以向相关应用程序提交补丁。

正如 Eric Florenzano 最近 指出的 Django 生态系统中存在缺陷。其中有几个。紧密耦合的“可重用”应用程序就是其中之一。埃里克还提出了补救措施,但需要时间才能实施。与此同时,您可以通过以某种方式树立榜样来帮助加速这一过程。

我知道,这个答案不太有帮助。我希望我有一个更好的答案。

Is it not customary to show confirmation messages to users?

Yes, it is.

Would it make sense for re-usable apps to also accept optional user messages as the view parameters?

Possibly, yes.

Wouldn't it be nice if re-usable apps used signals a lot more to allow hooking custom functionality?

Most certainly, yes.

what am I doing wrong?

You are using an app that does not meet the above criteria as well as it should. This is not entirely hard to fix. You could always roll your own app that meets the criteria you have set above. Alternately you can submit patches to the app in question.

As Eric Florenzano recently pointed out there are warts in the Django ecosystem. Several of them. Tightly coupled "reusable" apps is one of them. Eric also suggested remedies but they will take time to get rolling. In the meantime you can help accelerate the process by setting examples one way or the other.

I know, this answer is not too helpful. I wish I had a better answer.

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