Getting Started with Django - My Experiences

Submitted By: Josh Juneau

Introduction

You may ask why we need another web framework, or what a different web framework may do to make my applications or development life cycle better. Obviously the developers of the Django web framework had some key goals in mind when they set upon their journey to create Django. I believe that their goal was simplicity and ability. These are two of the key factors that come into play for many of today's web frameworks. Ruby on Rails was the one of the pioneers in this area. Not long after, many other great application development languages came up with similar powerful frameworks. For example, Grails is also gaining momentum in the Groovy/Java developer community.

Now we come to Python, one of the most sexy, powerful, and easy to learn object oriented languages of our time. Of course we have some great web frameworks for Python. Pylons and Django are just a couple. Now let's port those into the Jython arena and sprinkle a bit of Java into the Python mix to create some very attractive web frameworks. Django does not disappoint, and I'd like to argue that it is one of the leading frameworks in the simplicity and ability arena. Let's dig into some basics with Django and find out what makes this framework so appealing.

This article is meant for the Django beginner. More importantly, we will cover basics for getting started with Django development with Jython. Rather than develop a separate set of examples for getting started, we will follow the Django documentation and I'll add extra information as needed. I hope to pick up with more advanced topics in future articles, so please stay tuned to the Jython Monthly distribution for more details.

Getting Ready to Tango with Django

First things first, we have to set up our environment. For those of you who would like to follow along, please be sure to download the following before continuing:

- The latest Jython distribution (2.5 alpha 3 at the time of this writing) http://www.jython.org - Django (1.0 at the time of this writing) http://www.djangoproject.com/ - django-jython libraries http://code.google.com/p/django-jython/

You will want to install all of these and ensure that the they reside in your classpath. Please visit the [http://docs.djangoproject.com/en/dev/howto/jython/ Django on Jython documentation] for more details on setting up your environment.

Since we are using Jython, we can run our Django application on any Java servlet container. We can also mix any Java library into our application as needed...this is one of the most powerful reasons to use Django on Jython.

Database

Many of the major databases are supported at this time. However, there are a few that will not yet function with the Django framework on Jython. For instance, you will have to use an alternative to the DB2 database at this time. For more information, please take a look at the [http://code.google.com/p/django-jython/wiki/DatabaseBackends django-jython site]. For the purposes of this article, I am advocating the [http://www.postgresql.org Postgresql] database to start out with Django.

In order to make Postgresql work with Django in the Python world, you must install the [http://initd.org/pub/software/psycopg/ psycopg] package (bindings). However, we have a bonus as Jython developers as this package is not required to run Django with Postgresql on Jython. Instead, for the database engine we simply specify "doj.backends.zxjdbc.postgresql" within the settings.py module.

Creating the Project and Models

The first step in creating a Django application is to choose a location in which to store your code. Create a directory somewhere on your hard disk, and then open a command prompt or terminal. Change directories until you are positioned within your newly created directory. You also need to ensure that the jython and Django executables are in your CLASSPATH. Once you've ensured this information you are ready to begin creating your project.

Working with the Framework

== Delving into the Administrative Controls ==

Conclusion

References