django: ajax view structure

Posted by zack on Stack Overflow See other posts from Stack Overflow or by zack
Published on 2010-06-08T18:18:11Z Indexed on 2010/06/08 18:22 UTC
Read the original article Hit count: 293

Filed under:
|

I want to know the correct way to structure ajax views in django.

say i do something like :


def foo_json(request):
    if is.ajax():
        # return JSON here

and make it available as a resource at something like '/foo/data/'..

all is fine..

but if I point the browser at '/foo/data/' .. obviously I get an error (debug) like: app.views.foo_json didn't return an HttpResponse object.

so... my question is:

Whats the best way structure this kind of view?

..should I return an HTTP response code ..maybe 404 / 405 ... or something else? - not sure of the best way to handle this, any advice appreciated :)

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about django