brunch

매거진 백엔드

You can make anything
by writing

C.S.Lewis

by 내가 사는 세상 Jan 14. 2024

Django - shell

모델에서 데이터를 가져오는 간단한 작업을 할 땐 shell을 이용할 수도 있다.


(mysite) C:\iintheworld2>python manage.py shell

>>> from app_name.models import Category

>>> 



독립적으로 함수 실행하고 싶다면 다음과 같이 할 수 있다.




econ_data : 앱 이름

get_econ_data_to_db : views라는 폴더 안의 파일명

get_bok_date() : get_econ_data_to_db 파일 안의 함수명





python manage.py shell_plus --print-sql --quiet-load


--print-sql : 명령어에 대응하는 SQL문도 같이 보여줌

--quiet-load :  Django가 시작될 때 데이터베이스와 관련된 모든 앱의 models.py 파일을 자동으로 로드X. 장고 셸이 시작될 때 데이터베이스 모델을 로드하지 않아 초기화 시간이 단축

매거진의 이전글 Django - Form
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari