프로그래밍 학습/Python-Django 3.2
예제 | Function Based View
icf_
2023. 5. 29. 22:27
from django.shortcuts import render
#urls에서 views로 요청이 들어감.
# 매개변수가 request로 들어감.
def index(request):
# 이 변수의 값을 templates쪽으로 넘기기 위하여 값을 대입함.
posts = Post.objects.all().order_by('-pk')
return render(
request,
# 이 템플릿을 이용하여 렌더를 하시오.
'blog/Post_list.html',
{
# key: value 형태로 templates쪽으로 넘김
'posts':posts,
}
)
728x90