Reasons why to use Django

February 25th, 2010

First of all, what is Django? Django is high-level Python Web framework that was released under BSD license in 2005. It emphasizes re-usability, rapid development and DRY (don’t repeat yourself) principle.
There are a lot of great web development frameworks avaliable, like Ruby on rails and Codeigniter for PHP that follow same principles so we could say that Django is just another fast development web framework but with different flavor. And this is why I like this flavor best.

update 2010-02-28: I have added few more reasons, thanks to andrzejsliwa

1. Django is fast and stable

Django has been in use for quite a while now, and it works really well and it has been designed wit efficiency in mind. Here is a speed comparison between PHP Symfony, Ruby on rails and Django (quote: “Rails performed much better than Symfony. And Django performed much better than Rails.”).

And if that is still not fast enough for you, django has very easy to use cache ramework.

2. Object-relational mapper

You can avoid using SQL for most of the queries by using Django object-relational mapper. You describe your database tables entierly in python. You get a rich, simple and logical dynamic database-access.

Here are few examples. First we will define 2 models, comment and post, they will describe our database tables.

class Post(models.Model):
    title = models.CharField(max_length=100)
    text = models.TextField()
 
class Comment(models.Model):
    text = models.CharField(max_length=300)
    post = models.ForeignKey(Post)

And here is what we can do with them.

#Insert new post
p = Post(title = "My first post", text = "Lorem ipsum dolor sem...")
p.save()
 
#select all posts
Post.objects.all()
 
#select all comments that are related to first post
Post.ojects.get(id=1).comment_set.all()

These are just some basic commands, there is a lot more that you can do, you can find out more about django models here.

3. Django admin

Django can generate a very pretty and easy to use administration interface. It has support for foreign keys, many to many fields, file uploads, you can sort and filter and with little hacking you can get WYSIWYG editor inside django admin. You can also have multiple users with different permissions.
If you want to make a quick website with gread admin interface django is the way to go.

4. Fast development and code readability

Python is great language to build websites in, it’s easy to learn and easy to use. It has great syntax and a huge standard library (i have found HTML parser in standard library).
Django uses pretty SEO friendly URLs all the time, it has simple but powerfull template language that makes designers job easier, it makes working with forms easier and has full support for multi-language applications.

5. Django can scale

Django is being used for websites of all sizes, it can be used on shared hosting for smaller websites but it can also take loads of traffic on more powerfull servers. For example grono is a Polish social networking website with over 2,000,000 users, Django handles it all.

6. Documentation

Django has great documentation that is well organized and includes lots of examples. I should also mention django book, a set of very good django tutorials.

7. Explicit over implicit

“This, a core Python principle, means Django shouldn’t do too much “magic.” Magic shouldn’t happen unless there’s a really good reason for it. Magic is worth using only if it creates a huge convenience unattainable in other ways, and it isn’t implemented in a way that confuses developers who are trying to learn how to use the feature”

You can say that it’s matter of preference, but I really don’t like magic. I like to know how things work and for me it’s easier to learn and remember functions and methods if they are simple. Also, convention over configuration simply does not work for me, I like configuration – but i don’t like remembering conventions.

I understand that some people like magic and cleaner code you get by avoid configuration, and honestly if you are one of those people ruby on rails is the way to go.

blog comments powered by Disqus