점프 투 장고 2-4 79페이지

하다가 잘안돼서 질문 드립니다.

경로: C:\projects\mysite\pybo\views.py

from django.shortcuts import render
from .models import Question

def index(request):
    """
    pybo목록 출력
    """

    question_list = Question.objects.order_by('-create_date')
    context = {'question_list: question_list'}
    return render(request, 'pybo/question_list.html', context)
여기서 question_list  글자색이 회색으로 되어있고
objects가 강조표시가 되면서 확인되지 않은 'Question' 클래스 속성 참조 'objects'라고 오류가 뜹니다.


경로: C:\projects\mysite\templates\pybo\question_list.html
{% if question_list %}
    <ul>
        {% for question in question_list %}
            <li><a href="/pybo/{{ question.id}}/">{{ question.subject }}</a> </li>
        {% endfor %}
    </ul>
{% else %}
    <p>질문이 없습니다.</p>
{% endif %}

do it! 실습질문 목록 조회 구현하기 하기 전에는 '안녕하세요 pybo에 오신것을 환영합니다'가 출력된 상태였습니다.
위에 코드를 추가하고 새로고침을 하니
TypeError at /pybo/
context must be a dict rather than set.
이런 화면이 뜹니다.
어떻게 해결해야 할까요?

pop030206 958

M 2021년 3월 7일 6:09 오후

목록으로
1개의 답변이 있습니다. 1 / 1 Page

context = {'question_list: question_list'}context = {'question_list': question_list} 이렇게 바꾸어 보세요.

박응용

2021년 3월 7일 6:10 오후

감사합니다 꼼꼼히 살펴봤다고 생각했는데 아직 멀었네요 ㅜㅜ 다음엔 더 꼼꼼히 찾아보고 질문드리겠습니다:) - pop030206님, 2021년 3월 7일 11:46 오후 추천 , 대댓글