Django

              · · ·

Since I’ve got a few moments, and I’ve decided to actually write down some rants rather than deciding that I can’t be bothered to - I’m going to use some space to single the praises of Django.

I’ve been using Django for a couple of years now - since around the autumn of 2005, and as such, feel that I’ve got a pretty good grasp of how the framework works. I haven’t really hacked around that much with the innards of Django (although I did propose a patch), however, what I really like about this framework isn’t particularly the internals, but just the whole philosophy that there seems to be in terms of building a web application.

Let’s face it, when you sit down to write a web application, especially as a sysadmin or a network engineer - your primary motivation isn’t to write a web application, your motivation is to get some data out in a very easily readable format to some audience. So, you start looking at how your database should be designed (or retrofitting your code around an existing database), and you start writing code for updating one table, or grabbing data from another. Stop. This is where Django comes in. With Django, you just rapidly develop your data into a set of models, which can be related in a number of different ways - almost everything that you want to do (for generic data handling) can then be done straight from a generic Django view - without you having to go around writing a lot of code for really generic things. It really speeds up web application development.

I love the fact that Django has things like overloadable save(), and delete() methods for each model - it sounds fairly trivial, but it’s great to be able to have the application create the ports on a switch when it saves it into the database the first time - and remove them when the user removes the switch. I’ve found myself able to work on really quite complicated model layouts without getting too tied up in it, because it’s just a case of breaking it down simply into models.

I’ve got a couple of Django based projects that I’m maintaining (hint: you’re reading one of them). The other is a portal system for Catalyst2. I’ve been working on this system for almost 2 years now - it started out as a PHP application, and then morphed into Django when I discovered it. As a PHP app it was just unmanageable, because of the amount of code that I was having to write. Django’s inbuilt admin application has let me just worry about actually presenting data to users - and keeping the boring stuff (like adding data to simple database tables) out of the way of the application. It’s become a pretty complicated application.

The system tracks ISP assets, things like racks, servers, switches, routers, cabling…the list goes on. For servers it can control APC MasterSwitches via SNMP, it integrates into cacti for network graphs, it can access RANCID SVN repositories to obtain device configurations…I built an SNMP poller that collects traffic data, and produces billing data as both HTML and PDF. I’ve integrated it with our automated DNS and MX secondary system. The list is pretty huge (hence why this project is almost two years old!).

Before it sounds like I’m just trying to give a list of features that I’ve written into an application - I’ll get to the point. Django and python’s flexibility means that I’ve been able to sit down and write features, I haven’t had to sit down and write a lot of generic type functions that add entries to a database, allow them to be updated, and then save them, I haven’t had to handle how my site is going to be templated - I’ve written features. This is the massive difference for me using Django.

Sure, I could get this functionality with just about any framework out there - BUT, Django does this really well - there are very, very few things that you come across and say “Oh, I don’t like that” that you can’t change. I didn’t really like the authentication system that it uses by default - no worries, I can just replace it with an LDAP authentication system for our users, and use the Django one to provide application-specific privileges. Django does things easily, in a sane manner, that you can just code for. What’s even better, is it fits in with people like me - who just want to get an application out - but also it fits in with those guys who want to produce just the frontend part of the system - the templating language allows really simple creation of complex pages, without a steep learning curve.

I didn’t really plan this entry before I started, but I hope I’ve got across what I actually wanted to say, Django is a really great framework that’s very, very flexible. It’s also getting better, they’re carefully considering what’s added to it, and keeping it so that its very database neutral, and can fit into many, many development styles.

I’ve written >5,000 lines of just python code in my Django applications, and I’m still finding new and cool things that the framework can do - I really do recommend it for web application RAD!