Django: My Initial Thoughts

I've been unemployed since October and while I look for my next opportunity, I've been utilizing some of my spare time trying to improve my professional skills. One of the areas I've been most focused on is learning Python, and along with it, the very popular Django web application framework. Stepping away from PHP and into the Python domain is like stepping into a whole new world. Python's syntax isn't too hard to catch on to, but things are just done differently in the Python world. One thing that really struck me about Python is the amount of extra work involved in building a simple web application, and the many paths available to go about it. Compared to Python, PHP basically has a web framework built right in. All of the things that we take for granted in the PHP world require a decision at the very least in Python.

Enter Django. I wanted to start making a web application, and I wanted to see results now. The most logical path was to pick a framework to do the heavy lifting for me. Django brought along with it more weirdness, but also some comfort. First of all, Django is built on an MVC architecture (though no one associated with Django will ever admit that), which immediately added some familiarity. Coupled with a simple model API, the ball was really starting to get rolling. I've always believed that one cannot really learn a language without actually building something that interests them. With Django helping me write my first Python web application, I was on my way to learning Python.

The first thing that interested me was Django's URL configuration. Django takes regular expressions which URLs are compared against. Each expression is paired with a callback function, and the callback function that is associated with the first expression that matches the request URL is called. My friend Chris Shiflett is always going on about how important attractive URLs are, and here is a framework that actually forces the developer to consider URLs before anything will work. I have never seen URLs given such royal treatment by a web framework, and this is exactly the type of thing that I like about Django. As a matter of fact, the Python manifesto asserts that explicit is better than implicit, and that statement almost certainly lead Django's developers to handling URLs in this way.

Let's contrast the URL configuration with something that I do not care for much at all about Django. Django lacks support for composite foreign and primary keys. Certainly composite keys aren't the most often used feature of SQL, but if you read my last blog entry you can see that they do have their place. What is more frustrating is that the existing implementation of primary and foreign keys was seemingly conceived of without even the slightest consideration for future support of composite keys. Primary and foreign keys for a model are referenced everywhere in Django, and none of the existing code is conducive to being adapted for composite keys, making it very difficult to develop a feasible solution while maintaining backward compatibility.

Django makes up for this huge shortcoming with another killer feature: manage.py. A manage.py script is automatically created when you create a new Django project. This script is a collection of great tools for your project. With it you can do all of the usual stuff that you can do with Cake's command line tool, for example. Django takes it to a new level by offering the `shell` command. When you execute `python manage.py shell`, Django launches the excellent Python interactive shell, but it goes a step further. Django bootstraps the Python shell for your given project, making it easy to quickly test some code or play with the Django API. Django also offers a built-in development webserver, via the `runserver` argument to manage.py. I have never been a fan of command-line tools associated with web frameworks, but Django's adds undeniable value to an already powerful web application framework.

These are just my initial thoughts. There is a lot of Django left to learn, and I expect that I will write about it again in the future. For now, I encourage you to give Django a shot for your self. I'd love to hear your experiences with Django in the comments.


4 Responses to Django: My Initial Thoughts

  1. 13 Brian Dailey 11.12.2009 9:40 pm

    Keep digging with Django and I think it'll grow on you. I develop in PHP most of the time, but I've really grown to appreciate Ruby/Rails and Python/Django for their own merits.

  2. 14 Duo 11.12.2009 10:58 pm

    I've been wanting to build something of "interest" in Python for a while now also. What are you building anyways?

  3. 15 Rob Speed 12.12.2009 1:32 am

    It's crazy how much this sounds like something I'd write. I'm a PHP developer by trade, I've been unemployed since September, and during that time I've been learning Django.

    Your point about the lack of composite keys struck a chord with me. Having a meaningless auto-increment primary column in a table that handles many-to-many relationships feels dirty to me.

    One thing I really like about it is that it doesn't kid itself about MVC. One thing that's bothered me about the MVC concept in the context of a web framework is that the controller and view are 1:1. Django refreshingly kicks that tendency by combining the two below a layer of templates (the FAQ refers to it as MTV).

    The other thing I love is the built in admin interface. Out of the box it's completely free after defining the model, but it's still possible to alter it in any way you want.

    Django feels very logical and easy to understand. Compared to learning Zend Framework, it's been a dream. I look forward to using it for an opportunity to use it in a real project.

  4. 16 nasloan 14.12.2009 12:30 pm

    Duo: Right now I'm working on a student information and billing system for my friend's martial arts school. It's an interesting project that gives me a lot of opportunities to explore different ways of using python. Even better, there isn't much of a strict timeline, so there it's the perfect project for me try different things and sort of explore Django and Python. As the project gets further along I am certain that I will write more about it. My last entry is also about that project, though I changed the example to make it easier to understand.

Leave a Reply



About

User