본문 바로가기

Python_WEB/Try_Django

[Django]Save to the Database

반응형

CodingEntrepreneurs Django 강의 정리

django shell>

python manage.py shell

 

argument X>

from blog.models import BlogPost

obj = BlogPost
obj.title = 'This is my title'
obj.content = 'This is my content'
obj.save()

Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: save() missing 1 required positional argument: 'self'

 

argument O>

from blog.models import BlogPost

obj = BlogPost()
obj.title = 'This is my title'
obj.content = 'This is my content'
obj.save()

 

 

저장 후 title 확인>

obj.title

'This is my title'

 

저장 후 content 확인>

obj.content

'This is my content'

반응형

'Python_WEB > Try_Django' 카테고리의 다른 글

[Django] Model in a View  (0) 2020.06.15
[Django]Model to Django Admin  (0) 2020.06.14
[Django]Your First App  (0) 2020.06.14
[Django]Built-In Template Tags  (0) 2020.06.14
[Django]Template Context Processors  (0) 2020.06.14