Tuesday, June 1, 2010

Quick install guide Django.

 Install Python

Get Python at http://www.python.org

You can verify that Python’s installed by typing python from your shell; you should see something like :(on terminal)
#Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Remove any old versions of Django

If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.

Install Django

You've got three easy options to install Django:

Option 1. Get the latest official version

The latest official version is 1.2.1 Here's how to get it:
First, download Django-1.2.1.tar.gz. Then:
tar xzvf Django-1.2.1.tar.gz
cd Django-1.2.1
sudo python setup.py install

Option 2. Get the latest development version

The latest and greatest Django version is the one that's in our Subversion repository (our revision-control system). Get it using this shell command, which requires Subversion:

svn co http://code.djangoproject.com/svn/django/trunk/

After you get it

See the installation guide for further instructions.

Install Apache and mod_wsgi

Basic Configuration

Once you’ve got mod_wsgi installed and activated, edit your httpd.conf file and add:
WSGIScriptAlias / /path/to/mysite/apache/django.wsgi
The first bit above is the url you want to be serving your application at (/ indicates the root url), and the second is the location of a "WSGI file" -- see below -- on your system, usually inside of your project. This tells Apache to serve any request below the given URL using the WSGI application defined by that file.
Next we'll need to actually create this WSGI application, so create the file mentioned in the second part of WSGIScriptAlias and add:
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
If your project is not on your PYTHONPATH by default you can add:
just above the final import line to place your project on the path. Remember to replace 'mysite.settings' with your correct settings file, and '/usr/local/django' with your own project's location.


Get your database running

If you plan to use Django’s manage.py syncdbSELECT, INSERT, UPDATE and DELETEALTER TABLE privileges during syncdb but won’t issue ALTER TABLE statements on a table once syncdb permissions. On some databases, Django will need command to automatically create database tables for your models, you’ll need to ensure that Django has permission to create and alter tables in the database you’re using; if you plan to manually create the tables, you can simply grant Django has created it.

Installing an official release

  1. Download the latest release from our download page.
  2. Untar the downloaded file (e.g. tar xzvf Django-NNN.tar.gz, where NNN is the version number of the latest release). If you're using Windows, you can download the command-line tool bsdtar to do this, or you can use a GUI-based tool such as 7-zip.
  3. Change into the directory created in step 2 (e.g. cd Django-NNN).
  4. If you're using Linux, Mac OS X or some other flavor of Unix, enter the command sudo python setup.py install at the shell prompt. If you're using Windows, start up a command shell with administrator privileges and run the command setup.py install.
For more detial click here 

Creating a project

If this is your first time using Django, you’ll have to take care of someinitial setup. Namely, you’ll need to auto-generate some code that establishes aDjango project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings. From the command line, cd into a directory where you’d like to store your code, then run the command  django-admin.py startproject mysite. This wil lcreate a mysite directory in your current directory.
The development server Let's verify this worked. Change into the mysite directory, if you haven't already, and run the command python manage.py runserver. You'll see the following output on the command line: Validating models...
0 errors found.

Django version 1.0, using settings 'mysite.settings'
Development server is running at
Quit the server with CONTROL-C.

Database setup

Now, edit settings.py. It's a normal Python module with module-level variables representing Django
settings. Change the following keys in the DATABASES 'default' item to match your databases
connection settings.
ENGINE -- Either
  • 'django.db.backends.postgresql_psycopg2', 'django.db.backends.mysql' or 'django.db.backends.sqlite3'. Other backends are also available.
  • NAME -- The name of your database. If you're using SQLite, the database will be a file on your
    computer; in that case, NAME should be the full absolute path, including filename, of that file.
    If the file doesn't exist, it will automatically be created when you synchronize the database for the
    first time (see below).When specifying the path, always use forward slashes, even on
    Windows (e.g. C:/homes/user/mysite/sqlite3.db).
  • USER -- Your database username (not used for SQLite).
  • PASSWORD-- Your database password (not used for SQLite).
  • HOST --The host your database is on. Leave this asan empty string if your database server is on the
    same physical machine (not used for SQLite).
If you're new to databases, we recommend simply using SQLite (by setting ENGINE to
'django.db.backends.sqlite3'). SQLite is included as part of Python 2.5 and later, so you won't
need to install anything else.
While you're editing settings.py, take note of the
INSTALLED_APPS setting towards the bottom of the file. That variable holds the names of all Django applications that are
activated in this Django instance. Apps can be used in multiple projects, and you can package and
distribute them for use by others in their projects.

By default, INSTALLED_APPS contains the following apps, all of which come with Django:
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

1 comment:

  1. Thanks for this nice tutorial . I have successfully installed django now and I am also able to see the adming page. Thanks a lot . Keep up the good work .