On 8/2/06, Dan Shafer <[EMAIL PROTECTED]> wrote:
>  The second major factor in my design is the need for AJAX componentry and
> in that regard, at least, it *seems* TG has a strong upper hand, though it
> could clearly be implemented with some effort in Django. Can anyone address
> the degree of difficulty or level of effort involved in incorporating, say,
> the YUI library, for example, into Django in a sufficiently seamless way
> that I could Ajax-ify the components in my designs without jumping through
> too many hoops? Or have I perhaps just missed something valuable in my
> exploration of Django that suggests this isn't even a problem?

Apologies if this feels like it's directed at you, but I see the myth
of "Django can't do AJAX" a lot, and I think we have to dispel it.

Doing AJAX with Django is stupid easy. I'm a bit busy at the moment,
but I've published a simple working example (using YUI) and I'm in the
process of writing up all the aspects of how it works. The gist of it
is this:

* Write your view, and if it needs to respond to XMLHttpRequests, have
it serialize the response to XML or JSON. The tools in
django.core.serializers make this extremely easy -- simplejson is
bundled, so you can dump pretty much any Python data structure to
JSON, and we provide serializers for converting Django model instances
to JSON and/or XML.
* Pick a JS toolkit (Dojo and YUI are my favorites) and write the
front-end code to interact with your view(s).

Really. That's all there is to it.

I've taken a lot of flak for this, but I have always maintained, and
always will maintain, that this is just about all Django -- the
framework -- should be doing. The only other thing I'd like to see,
and we've already thrown around drafts of how it would work, is a "web
services"-style API which would generically expose access to Django
models for any sort of remote call, be it XMLHttpRequest or whatever.

I've gone on at length in my blog about hte reasoning behind this, but
it really comes down to just a few things:

1) There are plenty of really, really good JavaScript toolkits being
given away for free right now, and I don't think Django should favor
one or be opinionated about which one you should use; we should just
make it as easy as possible for *any* of them to talk to a
Django-powered backend.

2) Tools that try to "helpfully" generate JavaScript calls for you are
brittle and may not save as much time as you think.

3) All too often, they're used not for their actual benefits, but
because someone doesn't want to learn and/or write JavaScript. My
personal opinion is that certain types of laziness are good to have in
a developer (because they result in better, reusable, modular code),
but that this is not one of them.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to