2

After reading this article about separating server and client, Separate REST JSON API server and client? I want to know if this problem also exists in Django.

In Django, are these 2 separate phenomenons?

  1. Django is MVC. Take out the view, have django as the backend and just send JSON. Create a separate say Emberjs or Angularjs app. Make these clients access backend's REST resources. In this case, how can you put the projects together to deploy to Heroku? Can you just deploy a "JAVASCRIPT-HEAVY-CLIENT" to Heroku, and have it just talk to ur REST server?

  2. Since Django is MVC, don't completely take out the view, but integrate Emberjs/Angularjs into the View, but still use REST resources? In this way, you can put all the angularjs components/js files into the static folder and deploy to Heroku.

Are these the same? and realistically, how do you put them together to be able to deploy to Heroku?

Community
  • 1
  • 1
jdang634
  • 75
  • 5

1 Answers1

2

Heroku is a application server platform. It's not really designed to serve static code.

The approach I've previously taken is to build the Django part normally, and have a single view that serves out a bootstrap template for everything under the JS App root.

Say I have a {Angular,Ember} app living at mydomain.com/app/, then everything under that will serve the bootstrap template (which includes serialised values queried from database) and calls the JS boostrap method to startup your app, and then the app takes over routing from that point, and renders out it's views.

At this point, all the data for the views is coming from django-rest-framework/django-tasypie.

Using this method and leveraging django-pipeline & django-boto's S3 storage backend, You should be able to serve a decently sized project with Django & {Angular,Ember}

Thomas
  • 11,757
  • 4
  • 41
  • 57
  • So are you saying that what you should do, is create an Angular/Ember app and make it live at mydomain.com. Add all the responsive UI things there, and then have that app communicate with django rest framework on the backend? In this way we are completely getting rid of the View from Django right? – jdang634 Oct 04 '13 at 17:19
  • also, what role does django-pipeline and django-boto play in this and why is it necessary? – jdang634 Oct 04 '13 at 17:20
  • Hi, sorry I've taken so long to answer. Yes, I'm saying that you can serve an Angular/Ember app from your domain (or any sub-path thereof) and communicate with Django using a REST API. You're not entirely eliminating Django's View layer, because you'll likely want to embed information into that initial pageload (User's creds/permissions/feature-flags for example). django-pipeline is for compressing and combining JS resources into bundles that can significantly improve your pageload time. django-boto is for uploading these to S3. – Thomas Jan 21 '14 at 07:09