본문 바로가기
Web/django

(Django) first project 4 - View

by 스퀴시 2020. 8. 12.
728x90
SMALL

View는 application의 "logic" 을 결정하는 역할이다. MVC 패턴의 Controller에 해당하는 부분. 

실제로 Django를 처음 봤을 땐 MVC랑 조금 달라서 당황스럽다.ㅠ

 

개념부분에서 설명했지만, Django는 MVC랑 똑같지만 이름만 다른 MTV 패턴이다.

 

Model < -------------- > View < -------------------> Template

view는 views.py 파일안에 존재한다. 

 

views.py

Blog application 아래의 view파일에 post_index의 logic을 구성한다.

#blog/views.py

from django.shortcuts import render

# Create your views here.

# request를 받아서 render method를 호출하여 post_index.html을 render(보여줌)
def post_index(request):
    return render(request, 'blog/post_index.html',{})

file을 save했지만, 아직도 뭔가 부족하죠? 이제 실제 user에게 보여줄 html파일인 template 를 만들 차례!

 

다음 posting!!

LIST

'Web > django' 카테고리의 다른 글

(Django) ORM과 QuerySets  (0) 2020.08.13
(Django) first project5 - Template  (0) 2020.08.12
(Django) first project 3 - urls  (0) 2020.08.12
(Django)first project3 - Admin  (0) 2020.08.12
Django MySQL 연동  (0) 2020.08.11