Department of Computing

Local Navigation

COMP249 Web Technology: Django Notes

Firstly let me apologise for the late notice regarding cancellation of the guest lecture. I was unable to contact Malcolm and it now seems that he has had some personal issues that have meant he is out of email contact. These notes and the accompanying video lecture are intended to replace what Malcolm might have said.

What is Django

Django is a Python based web framework that provides a base on which to build modern web applications. Instead of having to do everything yourself, Django provides ways to manage common requirements like sessions, user authentication, databases, page templating etc. Django makes developing a simple web application a much easier and faster job. I will try to demonstrate this by writing a version of the bookmarker application in Django in a video.

Django is not the only such framework. For Python there are a number of others, probably most notable is TurboGears. In many ways the ancestor of this kind of package is Ruby on Rails which is based on the functional language Ruby. Rails was a bit of a revolution in terms of web frameworks a few years ago when it introduced the idea of a framework that wrote boilerplate code for you and made it easy to develop simple database backed web applications. PHP could also be considered a player in this space but plain PHP is more like plain Python - the tools are there but you put them together however you want. A better comparison would be the Zend Framework which is an object oriented framework "developed with the goal of simplifying web development while promoting best practices in the PHP developer community."

Django provides the following important components:

Sessions might be worth highlighting since you have been implementing these yourself lately. Every Django application tracks users via a session cookie that it stores in a session table just like you did. However, this is done behind the scenes and you don't need to do anything in your code to enable this. A session is created for every visitor, even if they aren't logged in. In your application you can make use of sessions by storing information in the users session object. For example, you might want to record the addition of an item to a shopping cart - you can just add it to the session object rather than having to create a specific database model. The next time that same user makes a request, the same session object will be available to you. There is no need to send cookies yourself, everything is managed for you. This is common to most application frameworks and is one reason why some experienced web programmers don't know what cookies are - they never had to deal with them; hopefully you will be wiser than them!

Video

Watch this Django screencast by Ian Millington showing how to create a simple blog application in a few minutes using Django. While lots of the detail is not explained it shows how easy it is to put together a simple application. Note the following points:

If you are interested, there are other screencasts about Django that you could watch. You could try out developing your own project by following the tutorial on the main Django site - or even just read through it to see the kinds of things that can be done.

Comments to: comp249-admin@ics.mq.edu.au

Copyright & Site information