momohumtolearnfree home Grab your ads here. Only $4.99 for one month

Let's Install Django on Debian Lenny

My special thanks to Blogger and Visitors. If You like this, please help us to share:
Digg Technorati del.icio.us Stumbleupon
Bookmark and Share

debian.pngdjango.gifImprove Our Site Using Django [Mysql, Apache, Mod_Python]


Django is an an open source application, is designed to develop quickly and automatically a python web. The facilities of Django are Object-relational mapper, Automatic admin interface, Elegant URL design, Template system, Cache System, Internationalization(Language support). This article will explain how to install Django on Debian Lenny Server. We will use Mysql as SQL to configure our database.

Let's do it :

  1. Install Mysql
    # aptitude install mysql-server mysql-client

  2. You will be asked about user and password when use it.

    • We want MySQL to listen on all interfaces, not just localhost.

      # vi /etc/mysql/my.cnf


      [...]
      # Instead of skip-networking the default is now to listen only on
      # localhost which is more compatible and is not less secure.
      #bind-address = 127.0.0.1
      [...]

    • Restart Mysql

      # /etc/init.d/mysql restart


  3. Install Apache And mod_python

    # aptitude install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-python


  4. Install Django on Debian

    # aptitude install python-django python-mysqldb

  5. Create Django Project (e.g. djangosite), for security reasons I create that project outside my document root (e.g. /home/mydjango)

    # mkdir /home/mydjango
    # cd /home/mydjango /usr/share/python-support/python-django/django/bin/django-admin.py startproject mydjango


    Directory djangosite will be created with some python files in it.
    Now with the project djangosite created, we can configure Apache. I open my vhost configuration in /etc/apache2/sites-available/default and place the following lines between the <virtualhost>...</virtualhost> container:

    #vi /etc/apache2/sites-available/default

    [...]
    <Location "/djangosite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On
    PythonPath "['/home/mydjango'] + sys.path"
    </Location>
    [...]

    <Location "/djangosite"> refers to the URL - meaning this configuration will be used if you use /djangosite in the URL (e.g. http://www.example.com/djangosite). You can change it with you want. Please adjust the other values (SetEnv DJANGO_SETTINGS_MODULE mysite.settings and PythonPath "['/home/mydjango'] + sys.path") to the name of your project and the path where it is located.

    Restart Apache

    # /etc/init.d/apache2 restart


    Now you can access http://www.example.com/djangosite in a browser.

  6. Connect To A MySQL Database From A Django Project
    We will create djangosite as database, and djangoadmin as admin for mysql.
    # mysql -u root -p


    CREATE DATABASE djangosite;
    GRANT ALL ON djangosite.* TO 'djangoadmin'@'localhost' IDENTIFIED BY 'djangoadmin_password';
    GRANT ALL ON mysite.* TO 'djangoadmin'@'localhost.localdomain' IDENTIFIED BY 'djangoadmin_password';
    quit;


    We will edit settings.py file in the project folder (e.g. /home/mydjango/djangosite) and modify the database settings, e.g. as follows:

    vi /home/mydjango/djangosite/settings.py


    [...]
    DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

    DATABASE_NAME = 'djangosite' # Or path to database file if using sqlite3.

    DATABASE_USER = 'djangoadmin' # Not used with sqlite3.

    DATABASE_PASSWORD = 'djangoadmin_password' # Not used with sqlite3.

    DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.

    DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
    [...]

Now, We have a django site that can help us to improve our site. I do not issue any guarantee that this will work for you.

Comments :

0 comments to “Let's Install Django on Debian Lenny”

Post a Comment

 

Tolearnfree Tags

Translator

Follow

The Directories of Tolearnfree