1. 기존 settings.py 파일에 있는 디렉토리레벨에 
settings 폴더를 만들고 하위에 __init__.py, base.py(기존 settings.py rename), 개발환경 settings_dev.py, 운영환경 settings_prd.py 생성

settings 
 └ __init__.py
 └ base.py
 └ settings_dev.py
 └ settings_prd.py

 

2. settings_dev.py,  settings_prd.py
------------------------------------------------------------
from .base import *

환경별 개별설정

 


3. base.py
------------------------------------------------------------
공통설정

 

4. cmd에서 서버기동 방법

C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>BlogVenv\Scripts\activate

(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>python manage.py runserver --settings=Blog.settings.settings_dev
Performing system checks...

System check identified no issues (0 silenced).
[DEBUG] [2020-03-24 23:10:27,984] (0.014) QUERY = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = SCHEMA_NAME()' - PARAMS = (); args=None

[DEBUG] [2020-03-24 23:10:27,998] (0.009) QUERY = "SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)" - PARAMS = (); args=None

[DEBUG] [2020-03-24 23:10:28,008] (0.009) QUERY = 'SELECT [django_migrations].[app], [django_migrations].[name] FROM [django_migrations]' - PARAMS = (); args=()

March 24, 2020 - 23:10:28
Django version 2.1.15, using settings 'Blog.settings.settings_dev'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.


5. eclipse에서 서버기동 방법2
Project > Properties > PyDev - Django
Django manage.py : manage.py 변경없음
Django settings module : Blog.settings-> Blog.settings.settings_dev 변경

Run As > PyDev: Django

 

6. shell 진입

(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>python manage.py shell --settings=Blog.settings.settings_dev

 

7. eclipse console에서 shell 진입

# eclipse에 환경변수 설정되어 있다면 아래 스크립트는 없어도 된다.
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Blog.settings.settings_dev')
'Blog.settings.settings_dev'

# 환경변수 설정되었는지 테스트
os.environ.get("DJANGO_SETTINGS_MODULE")
'Blog.settings.settings_dev'

from django.conf import settings
settings.BASE_DIR
'C:\\Work\\Software\\eclipse-jee-2019-12-R-win32-x86_64\\workspace\\blog.daonelab.com'

import django
django.setup()
from post.models import Post


Post
<class 'post.models.Post'>

eclipse에서 환경변수 설정
https://blog.daonelab.com/post/12/1600/

 

8. settings 분리되었을때 makemigrations

(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>python manage.py makemigrations --settings=Blog.settings.settings_dev


(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>python manage.py migrate --settings=Blog.settings.settings_dev