Rotiple



DB동기화와 Html 사용하기



본 서버는 다른 곳에 있기 때문에 testapp 이라는 프로젝트 그대로 app을 만들어 진행하겠습니다.



Django App 이란


목적을 가진 뭔가를 수행하는 애플리케이션(application)을 Django계에선 Django App이라고 부릅니다. Django project는 이러한 App이 하나 이상 조합물입니다.



01. DB 동기화 시키기


우선 Django App을 만들기전에 사용할 DB를 동기화 시켜주겠습니다. 저같은 경우는 sqlite3를 사용하겠습니다. Django 1.7이상 버전에서는 migrate 명령어를 1.6이하 버전에서는 syncdb를 사용하시면 됩니다.

# ./manage.py syncdb
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session

You just installed Django's auth system, which means you don't have any superusers defined.
Please enter either "yes" or "no": yes
Username (leave blank to use 'root'): root
Email address: a@a.com
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)


슈퍼유저를 생성하고 삭제하는 경우에는 다음과 같은 명령어를 사용하시면 되겠습니다.

# ./manage.py createsuperuser
# ./manage.py changepassword root



02. Django App 생성하기


project 생성과 마찬가지로 간단한 명령어로 생성이 가능합니다.
index페이지 기능을 하는 App 먼저 만들어 보겠다 .

# ./manage.py startapp admin


구조는 다음과 같이 생긴다

testapp/
├── manage.py
├── testapp/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
│   └── views.py
├── admin/
│   ├──__init__.py
│   ├──admin.py
│   ├──models.py
│   ├──tests.py
└   └──views.py


admin.py는 관리자 영역에서 이 App을 다루는 코드를 담는 모듈입니다. Django의 강점이자 매력 요소인데 나중에 다루도록 하겠습니다.

models.py은 모델을 정의하는 모듈인데 모델(model)은 데이터(data)를 구성하는 항목 자체(field)와 데이터를 다루는 행위(behaviour)를 포함한 것입니다.

render라는 기능을 통해 html을 사용하여 만들겠습니다.

'Web Programing > Python Django' 카테고리의 다른 글

Test페이지 구동 시켜보기  (0) 2015.06.23
Django란?  (0) 2015.06.23
개발 환경 만들기  (0) 2015.06.23