February 8, 2008

Why Django and Python just won my heart

Filed under: programming, python — Tags: , , , — Bart @ 9:21 pm

As of yesterday, I completed my first Django app. Django is a high-level Python web framework designed for rapid development and quick deployment. Did it deliver? Oh god yes.

Coming into this project, my Python skill was hurting. I had not written a real Python application in a few months and before that, I never had a solid grasp of Python to begin with.

So why did Django make me so happy? First off, in a weeks time, a few hours here and there throughout the week, I managed to: Create a fully functional website with ability to add new posts (Along with card specials, release schedules), polls, a simple member registration, and of course a fully functional admin panel that made it easy for my client to add content to their site. I did this all, with no knowledge of Django before hand!

Some highlights of the Django framework:

  • Installing and configuring Django takes about 15 minutes for a newbie. Download the project from SVN (At this point in its development, this is a good idea), untar it, modify some settings and you’re golden
  • Setting up a project is simple with manage.py, the core of Django’s management capabilities. Setup the project, then setup your first app, and within a minute you are ready to fly.
  • For each application, Django creates a views.py, models.py and urls.py. These three files are the core of your program and it makes it super easy. Define your table and any core functions in models.py for that application (Ie: News Posts app), setup the templates you will pump out in views.py, and urls.py is if you want to get down and dirty with url structures.
  • syncdb and django admin are amazing. I cannot stress this enough. Define your models in models.py, run syncdb and all your tables (including multi-relational ones!), primary keys, etc are ALL CREATED! I love it!
  • Once all your tables are created, login to Django admin and you have full functionality to play with all your data. If you setup a DateTime variable in your model, the admin displays that field with a nice Javascript calendar popup.
  • Python is a sexy language that you will love the more you use it. When I first began playing with Python it was ok, kind of cool, but nothing amazing. The more I learn about Python, the more I love it. I’ve used PHP for years and I honestly can’t bare to look at it after working with Python in the past few months.

There’s a reason why companies like Google and NASA have adopted some of their technologies around Python, because it is code sex. Yes, I like that term.

To try out Django, check out these resources:

  • The official Django project site has a great documentation and beginners tutorial.
  • The B-List has some good code example and tutorials for Python/Django.
  • #django on irc.freenode.net has some great people. Magus- is a total dick, but very helpful ;)
Powered By WordPress