I'm working on a Django application and I'm just trying to push data up to the front-end to display.
我正在研究Django应用程序,我只是想将数据推送到前端进行显示。
In my views.py
here's what I have:
在我的views.py这里是我所拥有的:
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)
Here, timeRange is a list that contains the following:
这里,timeRange是一个包含以下内容的列表:
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']
And then in my template (index.html
), I have the following loop:
然后在我的模板(index.html)中,我有以下循环:
<div class="row">
...
<ul>
{% for item in timeRange %}
<li>{{ item }}</li>
{% endfor %}
</ul>
</div>
However, despite the list being generated in the backend, nothing is being displayed on the webpage. I know the list exists, but Django's rendering engine won't display it.
但是,尽管在后端生成了列表,但网页上没有显示任何内容。我知道列表存在,但Django的渲染引擎不会显示它。
Am I missing something obvious here?
我错过了一些明显的东西吗?
Thanks,
谢谢,
G
G
1 个解决方案
#1
1
render_to_response
second parameter, should be a dict
containing your data, you are passing a list
.
render_to_response第二个参数,应该是包含你的数据的dict,你传递一个列表。
your render_to_response
should looks like this:
你的render_to_response应如下所示:
return render_to_response('studybug/index.html', {'timeRange':timeRange}, context)
#1
1
render_to_response
second parameter, should be a dict
containing your data, you are passing a list
.
render_to_response第二个参数,应该是包含你的数据的dict,你传递一个列表。
your render_to_response
should looks like this:
你的render_to_response应如下所示:
return render_to_response('studybug/index.html', {'timeRange':timeRange}, context)