Django was the planned focus of the first session of C³, which was held on October 19, 2008.
Contents
October 19, 2008 session
About Django
Django is a web application framework written in Python. It is software intended for developers building dynamic web sites such as a blog, a wiki, or a poll site -- typically database-backed applications.
Django includes many components that are mostly decoupled but are designed to work together. Components include a database ORM and abstraction layer, a regex-based URL dispatcher, a markup-agnostic templating language, abstraction of HTTP requests and responses, form generation and processing, an administration interface for database records, RSS and Atom feed generation, a session and user authentication framework, and more.
One aspect that has contributed to Django's popularity is its distinction of 'apps' versus 'projects'. A Django 'app' is intended to encapsulate some very focused set of features and avoid making project-specific assumptions. As a result, one will ideally end up with apps that provide reusable models, views, and templates that are useful for a variety of projects. For instance, there are third-party Django apps that handle user registration, tagging, voting, recommendations (based on the tagging and voting apps), versioning of database records, database schema evolution, and more. Many projects make use of several of these apps at once. Much like Python, Django has "batteries included" which makes many of these apps relatively small and easy to share.
Getting started
Here's the plan for getting up to speed at the session:
- Brian will introduce the Django architecture and codebase.
- We will each set up a local Django development environment (see below).
- Brian will introduce some sample Django applications that will help motivate various fixes and improvements.
Things to work on
Here are some things that we may want to work on, although we may also want to draw other ideas from the Django 1.1 features list, the list of sprint ideas, or any existing tickets.
Results
Each of us successfully set up a Django development environment, but we decided to spend most of our time working on a Django application called Django Scheduler, which is intended to support scheduling tasks in Django. We had some productive discussion about various aspects of the problem, but we didn't get a lot of code written.
Setting up a Django development environment
Requirements
- Linux, Mac OS X, or Windows
A database engine and Python adaptor such as SQLite
Python 2.5+ includes a SQLite adaptor -- see the database installation documentation
Recommended: setuptools, virtualenv
Preparing the environment
- In your terminal, create the environment:
$ virtualenv django-env or $ python virtualenv.py django-env
- Activate the environment:
$ cd django-env/ $ source bin/activate
or on Windows:> \path\to\django-env\activate.bat
- Check out Django trunk (or a branch, if you're testing one):
$ mkdir src $ svn co http://code.djangoproject.com/svn/django/trunk/ src/django-trunk/
See the development installation section for instructions on making Django accessible in your environment. From django-env/, this looks something like:
$ ln -s `pwd`/src/django-trunk/django `pwd`/lib/python2.X/site-packages/django $ ln -s `pwd`/src/django-trunk/django/bin/django-admin.py `pwd`/bin/django-admin.py
Creating a test project
Create the project skeleton. From django-env/:
$ cd src/ $ django-admin.py startproject testproject
- Make the project accessible in your environment:
$ ln -s `pwd`/testproject `pwd`/../lib/python2.X/site-packages/testproject
- Create a test application within the project:
$ cd testproject/ $ python manage.py startapp testapp
Configure settings for testproject by editing testproject/settings.py:
DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = 'testproject.sqlite' ... INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'testapp', )Export the location of testproject's settings module (useful for running tests):
$ export DJANGO_SETTINGS_MODULE='testproject.settings'
Running the Django test suite
From django-env/:
$ python src/django-trunk/tests/runtests.py -v 1
