Is hacky manually creating JSON and manually handling GET, POST instead of using the correct RESTful API for AJAX functionality?

I started building a Django application, but this probably also applies to other frameworks. In the Backbone.js methods that invoke the server (fetch (), create (), destroy (), etc.), Should I use a suitable RESTful API such as provided by Tastypie or Django-Piston? I founded it simpler and more flexible, just to build JSON in my Django views that map to some URLs that Backbone.js can use. Again, I probably don't use the full Tastypie / Django-Piston functionality.

I'm not ready yet to make a full RESTful API for my application. I would just like to use some of the AJAXy features supported by Backbone.js.

Pros / cons of this?

+3
source share
2 answers

Remember that REST is not equal to JSON. If I need your introduction in text/html, you should be able to provide me with this, otherwise you can add 415.

The best solution you use now is to use the middleware functionality provided by Django. No matter what your view meets, use the functionality of the Djangos middleware to respond to encoding in JSON, XML, or something else.

+3
source

ajax json-. apis . , , ( , , ).

, ajax- . serializers/request.is_ajax.
ajax django/jquery: http://webcloud.se/log/AJAX-in-Django-with-jQuery/ (, , )

+2

Source: https://habr.com/ru/post/1784102/


All Articles