Cappuccino,Django,AJAX,并将其整合在一起 - 检查我的架构! [英] Cappuccino, Django, AJAX, and fitting it all together - review my architecture!

查看:264
本文介绍了Cappuccino,Django,AJAX,并将其整合在一起 - 检查我的架构!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图让我的头脑在卡布奇诺附近。我想让我的StackOverview同行审查下面的体系结构,看看它是否有意义 - 目的是利用Django和Cappuccino的独特优势,而不用加倍技术重叠。



当Web浏览器请求一个友好的URL(例如/,/ articles等)时:




  • DJango's urls.py将此匹配到
    视图。

  • 视图,而不是做
    DJangos典型的工作,填写一个
    模板与本地人dict,

    返回小的stub '直接在
    a卡布奇诺应用程序中使用HTML。

  • 客户端收到Cappuccino HTML

  • 客户端请求存根HTML中提到的目标J JS
    URL

  • 执行最终用户应用程序并在浏览器中显示



浏览器现在有一个工作的应用程序当用户执行
从服务器请求某些东西时:




  • 浏览器将XMLHTTPRequest发送到URL。 >
  • Django的URLs.py与
    视图相匹配。

  • 视图可以正常工作,也可能与数据库模型进行交互。但是,Django不是返回一个模板,而是返回一些JSON。

  • 客户端收到JSON,
    做任何事情。



这是否有意义?我们仍然有友好的URL的好处,并且正在为我们创建数据库来建模我们的代码。然而,我们提供的是Cappuccino存根页面和JSON响应,而不是使用模板,以便给用户更像一个真正的应用程序,而不像HTML模板引擎。



有没有更好的办法呢?其他Pythonistas使用什么?感谢您的反馈。

解决方案

对于流量低的网站,使用Django的路由层将会很好,但如果您计划获得大量的流量,您可能会考虑让您的代理网络服务器处理存根。



至于其余的工作,TurboGears社区已经做了这么多年了我是一个TG提交者,这就是我通常使用的)。将字典返回到模板的TG体系结构使得这个很简单,因为你只是将'json'设置为模板引擎。



在Django中做同样的事情不是很多更复杂。只需使用序列化工具将结果写入响应,而不是使用



请注意,当您执行这样的架构时,如果您将所有应用程序逻辑保存在一个位置,那么管理更容易。在Django中放置一些应用程序逻辑,而浏览器中的某些程序会使事情相当快地开始变得凌乱。如果您将服务器视为愚蠢的持久层(验证/身份验证/授权除外),则使用寿命更容易。



FWIW,我发现Sproutcore更容易如果您对较重的非渐进式增强框架感兴趣,请与卡布奇诺(Cappuccino)合作。


I'm trying to get my head around Cappuccino. I'd like my StackOverview peers to review the architecture below and see if it makes sense - the aim is to utilize the unique benefits of Django and Cappuccino without doubling up where the technologies overlap...

When the web browser requests a 'friendly' URL (eg, /, /articles, etc):

  • DJango's urls.py matches this to a view.
  • The view, rather than doing DJangos typical work of filling in a template with the locals dict,
    returns the small 'stub' HTML used in a Cappuccino app directly.
  • The client receives the Cappuccino HTML
  • The client requests the Objective J JS URLs mentioned in the stub HTML
  • The end-user app is executed and displayed in the browser

The browser now has a working app. When the user does something that requests something from the server:

  • The browser sends an XMLHTTPRequest to a URL.
  • Django's URLs.py matches this to a view.
  • The view does it work, perhaps interacting with the DB model. But instead of returning a template, Django returns some JSON.
  • The client recieves the JSON, and does whatever it needs to do.

Does this make sense? We still have the benefit of friendly URLs, and the database being created for us to model our code. However rather than using templates, we're providing Cappuccino stub pages and JSON responses, in order to give users something more like a real app and less like an HTML templating engine.

Is there perhaps a better way of doing things? What do other Pythonistas use? Thanks for your feedback.

解决方案

For a low traffic site, using Django's routing layer would be fine, but if you plan on getting a significant amount of traffic, you might consider having your proxying webserver handle the stubs.

As for the rest, it works and the TurboGears community has been doing it for years (I was a TG committer so that's what I normally use). The TG architecture of returning a dictionary to a template makes this trivial since you just set 'json' as your template engine.

Doing the same thing in Django isn't much more complicated. Just use the serialization tools to write the result to the response rather than using the templating calls.

Note that when you do an architecture like this, it's considerably easier to manage if you keep all the application logic in one place. Putting some app logic in Django and some in the browser causes things to start getting messy fairly quickly. If you treat your server as a dumb persistence layer (with the exception of validation/authentication/authorization), life is easier.

FWIW, I find Sproutcore to be easier to work with than Cappuccino if you're interested in heavier non-progressive enhancement frameworks.

这篇关于Cappuccino,Django,AJAX,并将其整合在一起 - 检查我的架构!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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