본문 바로가기

Django

Django shell을 이용하여 source 실행 시키기

반응형

예제 1

$ python manage.py shell
Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post
>>> p = Post.objects.last()
>>> p.title
'시간 자동 저장'
>>> p.create_at
datetime.datetime(2022, 2, 17, 12, 48, 24)
>>> p.update_at
datetime.datetime(2022, 2, 17, 12, 57, 8, 1333)
>>> exit()

 

예제2

$ python manage.py shell
Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from blog.models import Post, Category
>>> Post.objects.count()
3
>>> Category.objects.count()
2
반응형