Django at 30,000ft: A Manager's View

Note: This article was originally published in the September 2008 edition of Python Magazine. It is published here edited only for formatting.

Django is a full-stack web framework based in Python that allows you to achieve fast turnaround times. "Full-stack web framework" basically means it comes with tools necessary to access information in your database(s), report that information back to the user and many of the other functions you need on an everyday basis when dealing with web applications.

This particular web framework came onto the scene in July of 2005 in a small town in Kansas. Born in the fast-paced world of online news, it quickly became a player in the Python web framework realm. Among others, there are three main benefits of using Django are: it's Python, it has some of the best documentation among all open source projects, and it handles administrative tedium well.

Django being fully Python is an often overlooked virtue of the framework. Python is open source and has a large number of modules available for use. This allows you to extend the abilities of the core language by using code that someone else wrote, all at no cost to you. There are hundreds, if not thousands, of modules that handle issues such as Excel integration, database interaction, and more.

Leveraging free code is useful because the software is already developed, there are several people are maintaining it, and, most importantly, you don't have to spend time writing it from scratch. Django was born in an industry where deadlines are the name of the game. Because of this, time to market was a huge obstacle the developers of Django sought to overcome. By limiting the amount of code you have to write, you can get your product to market that much quicker. As this ideology was a beginning design decision, its a core concept of Django's ideologies.

One of the anecdotal stories the core developers are keen on sharing is an instance, near the inception of Django, where a reporter came across a wealth of information related to crimes on the Kansas University campus. The team rapidly prototyped the data structures to hold the information and the reporter set out to enter the data. In the hour and a half it took the reporter to enter the data into the system, the team was able to build all of the functionality necessary to display the information online. While they were busy building the back-end logic, the design team was building a design for it and, within a matter of hours, everything was online. These are the sorts of fast deadlines that Django was built to handle.

Django has more in common with Python than just the programming language behind it. They both have some of the same founding principles. Python is overseen by the Python Software Foundation (PSF) and Guido van Rossum, the Benevolent Dictator for Life (BDFL). Similarly, Django has recently started its own organization, the Django Software Foundation (DSF) and is guided by two BDFL's: Adrian Holovaty and Jacob Kaplan-Moss. Python has contributers who work full time on the project and similarly, Jacob took a position doing just that; Improving Django full-time. One of the greatest strengths of both Django and Python is the documentation. There are several free online books for learning Python (such as Dive Into Python), and following in the same fashion, there was a book coauthored by the BDFLs and published by Apress that was released to the community at http://djangobook.com.

Speaking of free, my favorite feature of Django is the free administrative interface. By adding in one line of text to your settings file and uncommenting one line in another, you have a wonderfully crafted, great looking administrative panel, of which the main features are the built-in authentication, CRUD operations for your data structures, and easy extensibility.

This administrative interface goes far beyond scaffolding you might find in Rails or Rails-like products. By default, it is password protected. Once inside, you can manage users via a page from the main dashboard. You can assign them to a group (which can have its own set of permissions) or edit their permissions individually.

Beyond user administration, you have access to all of your registered applications (You register an application for the admin panel with 2 lines of code in the model). This provides the ability to add, update, or remove data from your models. One of the subtle touches to this data entry form is the ability to save a record and immediately return to the form to add another. While this isn't groundbreaking functionality, it is the attention to small details like this that make working with Django so much easier.

Another handy feature to the admin interface is its documentation portal. Tucked away in the top navigation is a link to documentation for all the models and views in your project. There is also documentation for the designer friendly templating system we'll go over shortly.

While the view gathers its documentation from the developer-generated docstring (similar to a javadoc), that isn't entirely the case for models. For the model documentation, it will grab the docstring as a descriptor, but it will also describe each field in your model, show the data type it contains (along with any qualifiers such as length) and use the developer-described tags (if any) to display helpful text for the function of each of the fields. If the developer chooses not to describe each of his field entries, the admin interface will do a bit of readability conversion. For instance, it changes lastupdate to "Last Update" for human-friendliness.

This hits on one of the great strengths of Django: the documentation. Any who have worked with an open source project know that documentation is one of the hardest things to come by. Good documentation, neigh impossible. The aforementioned Django book, along with several others both in print and near the presses offers fantastic documentation on the project itself. More than that, however, the documentation included on the website is among the best in the open source community. If there were a Pulitzer for documentation, these guys would have my vote.

Not only is the documentation fantastic, itÕs as living and breathing as the framework itself. As Django nears it 1.0 release, there was a large sprint of documentation in which many members of the community participated. The idea behind this movement is to take the body of documentation through a refactoring process separating out each relevant piece into easy digest chunks. The inherit benefit of this is when you're looking for help on Signals or Middleware, you can simply navigate to that section and be presented with only the subset of information on the topic you want. Ease of navigation, digestible chunks and greater community involvement are all very attainable goals for this effort.

In the same vein as human-friendly documentation, Django also allows for very attractive access to your applications in an often-overlooked area: the URL. We all have a few URLs bookmarked that look something akin to http://example.org/sports/story/pages.php?q=e93828ikjj&r=39282. While it does the job, it definitely lacks appeal. By using Django, you can craft urls similar to http://example.org/sports/national/nfl/chicago-bears-topple-titans which are both appealing to the eye and memorable. Not only do these look great to humans, but the web crawlers that power search engines also love this sort of descriptive URL.

As if some of the greatest documentation wasn't enough, they put it at your fingertips. Through the beautifully designed admin interface, Django provides access to the documentation of every view (controller, from MVC world). This really helps with the separation of designers and coders, optimizing the workflow for both positions. The developers don't have to answer questions from the designers and the designers can get an idea about what they have access to, without bothering the coders.

By having access to the administrative panel, designers can view the documentation that tells them what variables are being passed into their template and also some explanation on what the view actually does. Using this, designers can construct a complete template without having to ask several questions to the coder for each page on your site and, most importantly, without having to read code.

Jeff Croft, a designer who has worked for several award-winning companies, found the templating language made his work quite a bit easier. His favorite features of the templating system were that he couldn't break the application by playing with the design and he could do anything he wanted with the content without having to bother the programmer. He also liked that the programmer didn't have to bother him when making any code updates.

To make designers more productive, the template language allows for blocking out wireframes for a website very easily. The designer can develop a base template with blocks defined such as "bodycontent", "sidebar" or "footertext" which can then be populated by subsequent, child templates. This allows greater flexibility when altering the look of a website than having to update each page to alter the design.

You may be thinking, "Yea.. Django has some pretty neat features.. but does it scale?". Glad you asked. Django is powering some high-traffic websites such as Pownce (a social networking website), Washington Post (nationally read newspaper) and Curse Gaming (a portal for online multiplayer games like World of Warcraft). Of these sites, the best-documented system in terms of infrastructure and stats is Curse Gaming's. They have sustained over 600,000 requests an hour while serving almost all dynamic content. They average about 12 million monthly visits for a total of 3.5 million unique visitors. These are some pretty impressive numbers! They handle this sort of traffic through liberal uses of Django's caching (via memcache).

In terms of server setup, Django is pretty flexible in terms of what it can do. You can deploy applications on a variety of operating systems using large web servers like IIS and Apache or lesser-known servers such as lighttpd. Django is also fairly flexible in terms of the database it uses with support for PostgreSQL, MySQL, SQLite and Oracle. It is worth mentioning that while the framework can run on Windows, a linux-based operating system is preferred.

Now that you have an overview of what Django can do, you may be curious how to get your employees to buy in. The best way to do this would be to present the features of Django that are relevant to each individual's task.

For your front-end engineers, let them know that Django doesn't make assumptions on libraries so they're free to use jQuery, MooTools, or YUI. They can custom code CSS or one of the many grid frameworks that have been popping up. They can code valid (X)HTML in full standards compliancy.

For your programmers, you get to program in Python, which is a big win. With that, there are the various libraries such as the Python Imaging Library (image manipulation / creation), ReportLab (generate reports), and FeedParser (parse RSS feeds). Beyond that, there are several Django specific packages that are drop-in solutions for several commonly used applications such as tagging, comments, feed generation and, my personal favorite, the admin panel. Using these tools, programmers are increasingly prepared for productive coding sessions by being able to use existing libraries to handle the easy functions so they can focus on the difficult problems.

So we've established that Django is great for developers and makes the designers life much easier and productive. But what about you? What about management? Well its great for you too. When your employees are more productive, can accomplish more in less time, and make amazing applications, it makes you look good. A reputation of delivering products on time (or, dare say, early) and under budget is never a bad thing to have.

Django is one of the best tools for building web apps when time and flexibility is important. By leveraging the power and extensibility of Python and maximizing the productivity of your employees regardless of their function in managing the website, it allows products to go from concept to production lightning quick. If you are interested in more information about Django, head over to https://www.djangoproject.com for more in depth information and answers to any questions you may have.