2016-06-24 1 views
0

단위 테스트 성능에서 마이그레이션 문제 (Django Migration Error: Column does not exist)까지 실행하는 데는 여러 가지 이유로 디버그 도구 모음을 켜고 끄는 것이 유용하다는 것을 알게되었습니다.설정에서 동적으로 django debug_toolbar를로드하는 방법

환경 변수에서로드를 제어하는 ​​방법은 다음과 같습니다.

아니, 정말로 질문이 아닙니다. 내가 알고있는 요리법으로 생각하십시오.

답변

0

settings.py

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 

    #conditionally disable later on 
    'debug_toolbar', 
    #...my apps... 

) 

#disable if not in DEBUG or if $USE_DEBUG_TOOLBAR is not set. 
USE_DEBUG_TOOLBAR = bool(int(os.getenv("USE_DEBUG_TOOLBAR", 0))) and DEBUG 

#disable as well if running unit tests... 
pgm = os.path.basename(sys.argv[0]) 
if not USE_DEBUG_TOOLBAR or pgm.startswith("test") or pgm.startswith("nosetests"): 
    li = [app for app in INSTALLED_APPS if not app == "debug_toolbar"] 
    INSTALLED_APPS = tuple(li) 

과 명령 행 사용과 같습니다

export USE_DEBUG_TOOLBAR=1 && python manage.py runserver 
관련 문제