Archive for the ‘Django’ Category

Django

October 13, 2009

Download the Django:

http://www.djangoproject.com/download/

tar xzvf Django-1.1.tar.gz

cd Django-1.1.1

sudo python setup.py install

Download the python:

http://www.python.org/ or add/remove software

Download the Mysql:

Test:

checking the Django is install or not

$ python
>import django
it doesn't show any message so your installation is complete.

Workings on Terminal:
Create the directory any where.
step 1:

$ mkdir django_project

$ django-admin.py startproject mysite  

$cd ursite

$ python manage.py runserver
Validating models...
0 errors found

Django version 1.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[13/Oct/2009 03:06:27] "GET / HTTP/1.1" 200 2053

Using default link run the django.

step 2:

create the database in mysql
$ mysql -u root -p

mysql> create database ursite;

mysql> show databases;

step 3:

changes in settings.py(under  ursite directory)

DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'ursite'
DATABASE_USER = 'root'
DATABASE_PASSWORD = 'xxxxxxx' 



$ python manage.py syncdb

Creating models:
Create the models under mysite directory

$ python manage.py startapp polls

Edit the polls/models.py

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

Edit the setting.py file again add the line mysite.polls 
in INSTALLED_APPS

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'ursite.polls'
)

$ python manage.py sql polls

You should see something similar to the following 
(the CREATE TABLE SQL statements for the polls app)

$ python manage.py syncdb

Activate the admin site

The Django admin site is not activated by default – it’s an 
opt-in thing. To activate the admin site for your installation, 
do these three things.

1.Edit the setting.py file again add the line django.contrib.admin
 in INSTALLED_APPS
2.Run python manage.py syncdb
3.Edit your ursite/urls.py 
file and uncomment the lines that reference the admin – there 
are three lines in total to uncomment.

urls.py

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)
$ python manage.py runserver 

if you already start the server just refresh the browser, In URL add
/admin/ like http://127.0.0.1:8000/admin/


NOTES:
1.uysite is the project name
2.polls is the application name