Django chapter 1

Hi friends,
          Today I have started learning django from basics . I want to create a simple bookmarking site in django with project name bestsites_bookmarks . I have given the steps to be followed in django.

To create a project use :

$django-admin.py startproject bestsites_bookmarks



This command creates 4 files

They are : -  _init_.py , manage.py , settings.py and urls.py

To Create a Database for  bestsites_bookmarks :

Now open settings.py in editor . It will have django settings for bestsites_bookmarks
 
DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

Now we have to assign the database engine to sqlite3 which might be preinstalled along with python 2.7  . And we assign the database to be used in engine and a descriptive name for database name i.e, bookmarksdb

'ENGINE': 'sqlite3',
'NAME': 'bookmarksdb',

Now to populate the database with tables  , move to project folder and enter the command

$python manage.py syncdb

This will ask for the superuser to be created give yes and the username and password to be used.

Launching the Development Server

Now we can start the server using the command

$python manage.py runserver

now open the browser and type

http://localhost:8000/

It will show a screen like this : -

This url shows that it runs on port number 8000

To change the port number use the command

python manage.py runserver 5000 - > you can give a port number u like here.

No comments:

Post a Comment