วันพุธที่ 13 พฤศจิกายน พ.ศ. 2556

Steps to Initiate Django project in Eclipse

1. create project folder
cd ~/workspace
django-admin.py startproject myproject
cd myproject
python manage.py startapp myapp


<< result >>
~/workspace
   myproject
      myproject
         __init__.py
         settings.py
         urls.py
         wsgi.py
      manage.py
      myapp
         __init__.py
         models.py
         views.py
         tests.py


2. create project in Eclipse
Eclipse menu > File > New > PyDev Project
   Project name = myproject
   Don't configure PYTHONPATH <-- default settings
   Next >> Finish

<< result >>
myproject and myapp icon as folder


3. initialize project in Eclipse
Eclipse menu > Project > Properties > PyDev - PYTHONPATH > click "Add Source Folder"
   select "myproject" root folder

<< result >>
myproject and myapp icon as package

Eclipse PyDev Project Explorer > right-click package myapp > New > PyDev Package
   Source Folder = /myproject
   Name = myapp.models
repeat to create package myapp.views, myapp.utils


4. create database for project
   4.1 log in to MySQL as root
        mysql -h localhost -u root -p'rootpassword'
   4.2 create database with default character set and collation
        CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
   4.3 create user and grant privileges
        CREATE USER 'django_dbuser'@'%' IDENTIFIED BY 'djangodbpassword';
        GRANT ALL ON mydb.* to 'django_dbuser'@'%';
        CREATE USER 'django_dbuser'@'localhost' IDENTIFIED BY 'djangodbpassword';
        GRANT ALL ON mydb.* to 'django_dbuser'@'localhost';



5. modify DATABASES in settings.py for project database, e.g.
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mydb',            # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'django_dbuser',
        'PASSWORD': 'djangodbpassword',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}



6. modify INSTALLED_APPS in settings.py to use south
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'south',
)



7. syncdb
  python manage.py syncdb

ไม่มีความคิดเห็น:

แสดงความคิดเห็น