卡布奇诺,Django的,AJAX,而这一切配合起来 - 回顾我的建筑! [英] Cappuccino, Django, AJAX, and fitting it all together - review my architecture!

查看:171
本文介绍了卡布奇诺,Django的,AJAX,而这一切配合起来 - 回顾我的建筑!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的头周围的卡布奇诺。我想我的StackOverview同行审查下面的结构,看看它是否是有道理的 - 其目的是利用Django和卡布奇诺的独特优势,而不加倍那里的技术重叠...

在Web浏览器请求友好的URL(例如,/,/用品等):

  • 在Django的urls.py符合此一 视图。
  • 视图,而不是做 Django的典型填写一个工作 模板与当地人快译通,
    返回所使用的小存根HTML 直接卡布奇诺的应用程序。
  • 在客户端接收HTML卡布奇诺
  • 在客户端请求的目标ĴJS 网址存根HTML提到
  • 最终用户的应用程序被执行, 在浏览器中显示

浏览器现在有一个工作程序。当用户做一些事情,    要求的东西从服务器:

  • 在浏览器发送一个XMLHTT prequest到URL。
  • 在Django的URLs.py此匹配到 视图。
  • 在该视图它的工作原理,或许与数据库模型交互。但是,而不是返回一个模板,Django的返回一些JSON。
  • 在客户端临危的JSON和 做什么,它需要做的事情。

这是否有道理?我们仍然有友好的URL的利益,并正在创建的数据库,为我们模拟了code。但是,而不是使用模板,我们提供卡布奇诺存根页面和JSON响应,为了给用户更多的东西像一个真正的应用程序,而不像一个HTML模板引擎。

有没有可能做事情的更好的办法?做其他Pythonistas使用的是什么?感谢您的反馈。

解决方案

对于低流量的网站,使用Django的路由层就可以了,但如果你打算得到一个显著的流量,你可能会考虑让你的代理网络服务器处理存根。

至于其他的,它的工作原理和的TurboGears社会已经做了多年(我是一个TG提交者所以这是我通常使用的)。字典返回到模板的TG架构使得这个平凡的,因为你刚才设置JSON作为模板引擎。

在做Django的同样的事情是不是要复杂得多。只需使用系列化工具来编写结果到响应,而不是使用模板调用。<​​/ P>

请注意,当你做这样的一个架构,它要容易得多,如果你把所有的应用程序逻辑在一个地方管理。把一些应用程序逻辑的Django有的在浏览器中会导致事情开始变得凌乱相当快。如果你把你的服务器作为一个愚蠢的持久层(除验证/认证/授权),生活更轻松。

FWIW,我发现了SproutCore更容易的工作比卡布奇诺,如果你有兴趣较重的非渐进增强框架。

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.

这篇关于卡布奇诺,Django的,AJAX,而这一切配合起来 - 回顾我的建筑!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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