Wednesday, April 27, 2011

Re: Javascript frameworks with Django

In my experience you almost definitely do want to take advantage of
templates. It makes things a lot easier.

Simple example:

A main template (including things like the <html> and <body> tags
and doctype).

A detail template that just includes, say, a table of results.

In action:

The user takes action on the page.

JavaScript does an AJAX call, which hits your Django view.

The Django view returns a rendered template.

The JavaScript callback function replaces a portion of the DOM with
that response.

Simple jQuery example of this:
$.ajax({
url: url_to_your_view,
type: "POST",
data: $("#search_form").serialize()
success: function(data){ $("#results_pane").html(data);},
});


Of course, you will probably have other bits and pieces of AJAX that
deal with JSON and change other aspects of the page, but for the
requirement of simulating a desktop application you will definitely have
a much easier time with it if you use templates as much as possible
instead of using JavaScript to dynamically write all your HTML.

Shawn


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment