pyvote/view.py에서
# 설명용
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
# 추가
from .models import Question
def index(request) :
# 추가: Question 모델 데이터 작성일시 역순 조회
# 검색 뒤 변수에 넣음
question_list = Question.objects.order_by('-create_date')
# 변수에서 정보를 받아옴(context)
context = {'question_list': question_list}
# return으로 보내줌
return render(request, 'pyvote/question_list.html', context)
# return HttpResponse("안녕하세요. pyvote 페이지 입니다.")
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from .models import Question
def index(request) :
question_list = Question.objects.order_by('-create_date')
context = {'question_list': question_list}
return render(request, 'pyvote/question_list.html', context)
127.0.0.1:8000/pyvote 방문 시
jango 안에 templates 폴더 추가
config/settings.py에서
'DIRS': [BASE_DIR / 'templates'],
jango 폴더 안에 templates 폴더 안에 pyvote 폴더 만들기
비주얼 스튜디오 코드에서