Created
December 8, 2015 03:04
-
-
Save initialkommit/a7c17c528f219f821f0c to your computer and use it in GitHub Desktop.
Django 프로젝트 setting을 위한 함수
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
""" | |
settings 유의사항 | |
1. Development와 Production을 다르게 구성하기 | |
1-1. DATABASE | |
1-2. SECRET_KEY: Production에서는 시스템 환경변수로 | |
1-3. DEBUG | |
virtualenvwrapper를 이용해 환경변수 세팅하기 예제 | |
1. postactivate | |
export DJANGO_SETTINGS_MODULE="project.settings.dev" | |
export SECRET_KEY="SECRET_KEY" | |
export DATABASE_NAME="project_db" | |
export DATABASE_USER="project_db_admin" | |
export DATABASE_PASSWORD="project_password" | |
2. predeactivate | |
unset DJANGO_SETTINGS_MODULE | |
unset SECRET_KEY | |
unset DATABASE_NAME | |
unset DATABASE_USER | |
unset DATABASE_PASSWORD | |
""" | |
import os | |
from django.core.exceptions import ImproperlyConfigured | |
def get_env_variable(var_name): | |
"""시스템 환경변수를 가져오기 위한 함수""" | |
try: | |
return os.environ[var_name] | |
except KeyError: | |
error_msg = "Set the %s environment variable" % var_name | |
raise ImproperlyConfigured(error_msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment