Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

http://stackoverflow.com/questions/10941249/separate-rest-json-api-server-and-client

In light of this post, I wanted to ask questions regarding Django and specifically the implementation methods of getting one of these client side technologies to work with Django.

Currently, I have a backend that is setup that uses Django Rest Framework to serialize the data. My problem though, is I'm not sure how to get the client side to access the backend.

Django is a MVC framework. Originally I thought that I could just take out the View, and just implement the model and controller. Then, I would write complete separate View code so to speak using Backbone/Ember/Angularjs. Then the client would access the REST resources. How would I combine these two later if I wanted to deploy this to Heroku? Heroku only takes a whole Django application. How can I get the client code on there as well then?

The other option, which I've seen before, is to NOT take out the View completely, but to use Django templates WITH Backbone/Ember/Angularjs. Then, I can just simply put these js files in the "static" folder so to speak. But then that seems weird, because then I'd have a View on the server side (correct me if I'm wrong), that accesses my own REST resources. I tried this, but for some reason even though my page retrieves the javascript files, it does not seem to be working as expected.

share|improve this question
 
a general advise: it seems that most of your problems arise because of names. forget about naming things ("this is a view", "this is a controller", "this is MVC"...) and focus on the implementation. –  Javier Oct 4 at 19:16
add comment

1 Answer

In order to get this type of app to work, you need to firstly go more in-depth into how the API setup works. APIs are different to the normal apps you can build in frameworks like Django or Rails (even though there's elements of APIs in these frameworks).

In order to explain a bit more, you can run your client-side JS framework being hosted on a static host (something like: http://www.divshot.io/)

You can then interact with Heroku (your backend) via API calls ('GET', 'POST', 'UPDATE' requests). This interaction would normally occur through something like JSON (where the elements are 'pulled' from the API, the client 'does something' to the element and the updated element is 'pushed' back via the API - making the database update).

Take a look at this question I asked a while back:

http://stackoverflow.com/questions/17760128/is-a-restful-api-and-a-backend-service-like-parse-the-same-thing

And also take a look at this guys tutorials concerning APIs:

http://coenraets.org/blog/2012/10/nodecellar-sample-application-with-backbone-js-twitter-bootstrap-node-js-express-and-mongodb/

These will help you somewhat in getting to understand APIs (those tutorials are especially useful).

If I remember from those tutorials, you can host your static client-side JS framework together with your backend on the same setup.

Just ask the guys at Heroku to clarify that for you, as I'm sure it will be possible to host the static JS/HTML/CSS on the same setup too.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.