Django, REST and Angular Routes Django, REST and Angular Routes django django

Django, REST and Angular Routes


The question isn't really specific to Django - just a matter of understanding the relationship between back-end and front-end in an SPA.

Routes are not duplicated between the back-end and the front-end. Your Django routes should be set up like:

/api/foo/api/bar...

and one single route that delivers a single page full of HTML partials, e.g.

/

The rest of the routes will be defined in Angular, e.g.

/articles/234/blog/date/slug...

The Angular controllers that handle those public-facing routes will in turn make $http calls against the API URLs and each will deliver one Angular partial. So there is no duplication, no overlap.

To the second part of your question, you can still use the Django ORM model relationships when constructing your API data, but yes, you'll lose all of that Django goodness when building the front-end.

If you build your API right, all of the data you need in each view will be fully present in the JSON feed that Angular consumes in that view. So you're using the ORM for back-end data construction, but you can't just decide to traverse a model relationship in a template without first preparing the back-end data to provide data for it.

Yes, it's a very different way of thinking of things, and yes it's quite a bit more complex than doing straight Django (or Rails). That's the cost of building a web app rather than a web site.