본문 바로가기

django 모듈을 파이썬 소스에서 실행할때..

오토씨 2022. 2. 15.

>>> from django.utils import timezone
>>> now = timezone.now()
....
django.core.exceptions.ImproperlyConfigured: Requested setting USE_TZ, but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

이런 로그를 뿌린다면, 아래 처럼 해보렴...

>>> import os
>>> from django.utils import timezone
>>> os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
>>> 'config.settings'
>>> now = timezone.now()

'config.settings'로 입력한 이유는...
프로젝트 생성시 입력한 프로젝트 name이 config임.

$ django-admin startproject config .

'dev > Python' 카테고리의 다른 글

딕셔너리에서 삭제하기  (0) 2022.03.08
defaultdict  (0) 2022.03.04
macOS에서 django 개발환경 셋팅하는 순서  (0) 2022.02.12
Windows에서 pip.ini 설정하기(proxy)  (0) 2022.02.08
Unicode HOWTO  (0) 2016.05.10

댓글