Cappuccino, Django, AJAX, and all this together - view my architecture!

I'm trying to raise my head around Cappuccino. I would like my StackOverview peers to look at the architecture below and find out if it makes sense to use it - the goal is to take advantage of the unique benefits of Django and Cappuccino without double the size of the technology overlap ...

When a web browser asks for a "friendly" URL (for example, /, / articles, etc.):

  • DJango urls.py matches this view.
  • Representation, rather than execution, A typical DJangos job of filling out a template with a locals dict,
    returns a small HTML stub used directly by the Cappuccino application.
  • Client receives Cappuccino HTML
  • Client requests Object J JS object URLs mentioned in HTML stub
  • The end-user application runs and displays in the browser

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

  • The browser sends the XMLHTTPRequest to the URL.
  • Django's URL matches this View value.
  • The view works, possibly interacting with the database model. But instead of returning a template, Django returns some JSON.
  • The client receives JSON and does everything that it needs.
It makes sense? We still use friendly URLs and the database we create to model our code. However, instead of using templates, we provide Cappuccino stub pages and JSON responses to give users something more than a real application and less like an HTML template engine.

Is there a better way to do something? What do other pythonists use? Thanks for your feedback.

+6
json ajax django model-view-controller cappuccino
source share
1 answer

For a low-traffic site, using the Django routing level would be great, but if you plan to get a significant amount of traffic, you might want your proxy to handle stubs.

As for the rest, it works, and the TurboGears community has been doing this for many years (I was a TG committer, so I usually use that). The TG architecture that returns the dictionary to the template makes this trivial as you simply set json as the template engine.

Doing the same thing in Django is not much more complicated. Just use serialization tools to write the result in response, rather than using templating calls.

Please note that when you perform a similar architecture, it greatly simplifies management if you keep all the application logic in one place. Putting some application logic in Django, and some in the browser make things get confused quickly. If you consider your server as a dumb level of persistence (except for verification / authentication / authorization), life is easier.

FWIW, I believe that Sproutcore will work easier than Cappuccino if you are interested in heavier infrastructures without progressive improvement.

+4
source share

All Articles