Saturday, June 16, 2007

Begin Django.

Let’s verify this worked. Change into the mysite directory, if you haven’t already, and run the command pythonmanage.pyrunserver.

Changing the port

By default, the runserver command starts the development server on port 8000. If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080:

DATABASE_ENGINE — Either ‘postgresql_psycopg2’, ‘mysql’ or ‘sqlite3’. Other backends are also available.

DATABASE_NAME — The name of your database, or the full (absolute) path to the database file if you’re using SQLite.

DATABASE_USER — Your database username (not used for SQLite).

DATABASE_PASSWORD — Your database password (not used for SQLite).

DATABASE_HOST — The host your database is on. Leave this as an empty string if your database server is on the same physical machine (not used for SQLite).

sudo aptitude install python-psycopg2

By default, INSTALLED_APPS contains the following apps, all of which come with Django:

django.contrib.auth — An authentication system.

django.contrib.contenttypes — A framework for content types.

django.contrib.sessions — A session framework.

django.contrib.sites — A framework for managing multiple sites with one Django installation.

These applications are included by default as a convenience for the common case.

Each of these applications makes use of at least one database table, though, so we need to create the tables in the database before we can use them. To do that, run the following command:

python manage.py syncdb

For the minimalists

Like we said above, the default applications are included for the common case, but not everybody needs them. If you don’t need any or all of them, feel free to comment-out or delete the appropriate line(s) from INSTALLED_APPS before running syncdb. The syncdb command will only create tables for apps in INSTALLED_APPS.

What’s the difference between a project and an app? An app is a Web application that does something — e.g., a weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects.