[Django]-Is it hacky to manually construct JSON and manually handle GET, POST instead of using a proper RESTful API for AJAX functionality?


Remember, REST does not equal JSON. If I require your representation in text/html, you should be able to provide me with that, or else throw a 415.

A better solution, then you are currently using, is to use the middleware functionality that Django provides. Whatever your view replies, use Djangos middleware functionality for the response to encode into JSON, XML or whatever.



I personally prefer defining my own ajax views and json objects. Using some already apis developed may be or may not be of much use. Some don’t exactly fulfill the requirements some may have features which are redundant (And I don’t like a code to be present which is not being used).

Also writing ajax functionality is not that difficult either. The inbuilt serializers / request.is_ajax features are there for your help.
Some examples for ajax implementation with django/jquery: http://webcloud.se/log/AJAX-in-Django-with-jQuery/ (You most probably have seen it already)

Leave a comment