Sunday, November 25, 2007

Django - the "D" is silent

"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design".

I am quite new to different frameworks and this is probably the first Open Source framework I've actually used for anything. I've heard that there are other frameworks that offer similar things - like Ruby on Rails; however, I've never actually used any of them, so Please keep in mind that my opinion may be a bit biased.

Django tries to keep everything automated and adheres to something called the Dry Principle. It makes life so much easier when creating database designs that I'm pretty impressed. From what I've experienced, it can create full database structures, administrative logins/web pages given object specifications (similar to normal OO Programming Syntax); on top of that you can design urls with minimal code.

Here is an example of an object model (taken from the Django tutorials) used to create the database:
from django.db import models

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Admin:
pass
As you can see from the example, that is how you would create a table called "Poll" with two fields - question and pub_date. Now you can login to the administrator page (already automated) and add as many new polls as you like; simple right? You could even use python shell or a script, and create it like you would a class object. Like this:
p = Poll(question="What's up?", pub_date=datetime.datetime.now())
If you ever wanted to create a simple website or blog, you should check Django out. Try a few tutorials and see what it has to offer for yourself; if you have any trouble login their irc #django IRC channel on irc.freenode.net. There's a lot of nice people there who are more than willing to help out.

No comments: