DjangoCon, Django Rest Framework, and AngularJS

DjangoCon was held over the course of last week in Portland, Oregon. Myself and several other team members attended this annual convention regarding all things Django. It’s a great opportunity to go and discuss the nature of your projects and the assorted challenges that might come with them. There’s a great deal of cross-pollination of ideas and plenty of opportunities to explore new concepts. One of the most popular topics we saw at the conference was the Django Rest Framework and different ways you could utilize it to create an API for your projects. It’s a tool we use extensively at Tivix, and I encourage you to read Kyle Connors’ recent post on API design.

Another popular topic at the conference was in how AngularJS could be used with Django to build single page apps (SPAs.) It’s a topic we’re very familiar with at Tivix, where we’ve built half a dozen of these apps over the course of the past year and a half. This is a strategy that makes sense as more and more focus is placed on mobile platforms. At some point, your app is going to need an API to be able to support mobile apps. Building your website as a single page app allows you to focus on building that API up front, rather than duplicating your efforts to build a website and then replicating the functionality with an API. With a single page app, your website can be constructed in much the same way as a mobile app.

At DjangoCon, one of the common challenges was in how and where to bring Django and AngularJS together. For many developers, the impulse is to continue using Django for as much functionality as possible. It provides many great tools, and developers who are getting underway with a SPA will feel more comfortable with it. This is a strategy that you want to avoid, though. AngularJS provides its own toolset, and offers its own opinions specifically on how to build a SPA. If these two frameworks aren’t kept separate, then they will come into conflict. It might be helpful to think of it like this: you wouldn’t use Django to build out your iOS or Android apps — why would you use it to build out a single page app? Let each framework focus on what it does best.

One particular challenge that was expressed by attendees several times at the conference was the difficulty in trying to manage user authentication in a single page app. Out of the box, Django Rest Framework doesn’t provide support for Django authentication tools. This might mean you have to create those tools yourself, and then determine how to integrate it with AngularJS. We’ve been there, and we’ve tried to solve the problem once and for all with the open source Django Rest Auth project. It provides the tools you need to drop in support for Django authentication over the rest framework. In addition, we’ve also built an AngularJS module which is designed to integrate with Django Rest Auth to provide a seamless experience while building your SPA.

I gave a lightning talk on the last day of the conference outlining our experience over the last 18 months. The slides have been embedded below. Django and AngularJS are a winning combination for building SPAs, and we’re excited to see what the community comes up with for next year’s conference.

DjangoCon, Django Rest Framework, and AngularJS

Leave a Reply

Your email address will not be published. Required fields are marked *