2015-02-06 6 views
0

Django 응용 프로그램을 만들고 있는데 프론트 엔드에 데이터를 표시하려고합니다. 여기 내 views.py에서Django에서 내 템플릿을 렌더링하지 않는 이유는 무엇입니까?

내가 가진 무엇 : 나는 다음과 같은 한 내 템플릿에 다음

timeRange = ['Room 203A 10:00 AM \xc2\xa0', 'Room 203A 10:30 AM \xc2\xa0', 'Room 203A 11:00 AM \xc2\xa0', 'Room 203A 11:30 AM \xc2\xa0', 'Room 203A 12:00 PM \xc2\xa0', 'Room 203A 12:30 PM \xc2\xa0', 'Room 203A 3:00 PM \xc2\xa0', 'Room 203A 3:30 PM \xc2\xa0', 'Room 203A 4:00 PM \xc2\xa0', 'Room 203A 4:30 PM \xc2\xa0', 'Room 203A 5:00 PM \xc2\xa0', 'Room 203A 5:30 PM \xc2\xa0', 'Room 203A 6:00 PM \xc2\xa0', 'Room 203A 6:30 PM \xc2\xa0', 'Room 203A 7:00 PM \xc2\xa0', 'Room 203A 7:30 PM \xc2\xa0', 'Room 203A 8:00 PM \xc2\xa0', 'Room 203A 8:30 PM \xc2\xa0', 'Room 203A 9:00 PM \xc2\xa0', 'Room 203A 9:30 PM \xc2\xa0', 'Room 203A 10:00 PM \xc2\xa0', 'Room 203A 10:30 PM \xc2\xa0', 'Room 203A 11:00 PM \xc2\xa0', 'Room 203A 11:30 PM \xc2\xa0'] 

그리고 (index.html) : 여기

def index(request): 
    ... 
    context = RequestContext(request) 

    rooms = dict(db.studybug.find_one()) 

    timeRange = [room.encode('utf-8') for room in rooms['timeRange']] 

    return render_to_response('studybug/index.html', timeRange, context) 

, timeRange에는 다음이 포함 된 목록입니다 루프 :

<div class="row"> 
    ... 
    <ul> 
    {% for item in timeRange %} 
     <li>{{ item }}</li> 
    {% endfor %} 
    </ul> 

</div> 

그러나 목록이 g 백엔드에서 실행되면 아무 것도 웹 페이지에 표시되지 않습니다. 나는 목록이 존재한다는 것을 알고 있지만, 장고의 렌더링 엔진은 그것을 표시하지 않을 것입니다.

내가 여기에 뭔가 분명한 것을 놓치고 있습니까?

감사합니다,

G

답변

1

render_to_response초 매개 변수는 dict 당신의 데이터를 포함, 당신이 list을 전달하는 있어야한다. 이 같은

당신의 render_to_response해야 외모 :

return render_to_response('studybug/index.html', {'timeRange':timeRange}, context) 
+2

'timeRage'' 좋은,하지만 당신은'로 변경 할 수 있습니다 'timeRange''. – Matthias

+0

@Matthias done, thx bud. – levi

관련 문제