manage.py : 사이트 관리를 도와주는 역할을 하는 스크립트이다. 다른 컴퓨터에서 다른 설치 작업없이 웹 서버를 시작할 수 있다.(추후에 관련 정보 update)
config/ : 디렉토리 내부에 프로젝트를 위한 실제 python 패키지들이 저장된다.
config.urls , config.settings 다음과 같이 프로젝트 내부 어디에서나 접근(import)할 수 있다.
config/__init__.py : 해당 디렉토리가 패키지의 일부임을 알려주는 역할을 한다.
python version 3.3 부터는 __init__.py 가 없어도 패키지로 인식이되지만, 하위 버전과 호환을 위해 생성하는 것이 안전하다.
config/settings.py : 현재 Django 프로젝트의 환경/구성을 저장한다.(추후에 관련 정보 update)
config/urls.py : 현재 Django 프로젝트의 URL선언을 저장한다. urlresolver가 사용하는 패턴 목록을 포함한다.(추후에 관련 정보 update)
config/wsgi.py : 현재 프로젝트를 서비스하기 위한 WSGI config 설정파일이다.
WSGI(Web Server Gateway Interface)
웹서버와 파이썬 웹 애플리케이션 개발환경 간의 인터페이스에 대한 규칙이다.
여기서 설치된 pip 패키지 목록을 requirements.txt 로 남겨두어 관리하는 것이 좋다.
$ pip freeze > requirements.txt
project
├── project_name
│ ├── config # 장고프로젝트 설정 패키지
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── db.sqlite3
│ └── manage.py
└── requirements.txt # 설치할 pip 패키지 목록 파일
프로젝트 서버
서버 시작하기
$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
March 05, 2019 - 16:21:39
Django version 2.1.7, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
runserver를 성공하면 http://localhost:8000/ 또는 http://127.0.0.1:8000/ 로 확인 할 수 있다.
migrate 명령은 settings.py 의 INSTALLED_APPS 설정을 탐색하여, 데이터베이스 migrations에 따라 필요한 데이터베이스 테이블을 생성한다.
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
migrate하기 전에 불필요한 애플리케이션(INSTALLED_APPS)은 주석처리 또는 삭제해주면 생성되지않는다.
ModuleNotFoundError
....
File "/Users/jeongdaye/.pyenv/versions/3.7.2/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'