在我的浏览器中,一切都很好。直到我做一个测试
这是我的民意调查/views.py
from django.shortcuts import render
from polls.models import Poll
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')
context = {'latest_poll_list':latest_poll_list}
return render(request,'polls/index.html',context)
民意调查/模板/民意调查/index.html
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>{{poll.question}}</li>
{% endfor %}
</ul>
{% else %}
<p>No Poll Available</p>
{% endif %}
和我的 polls/tests.py
from django.test import TestCase
from django.core.urlresolvers import reverse
class SimpleTest(TestCase):
def test_this(self):
response = self.client.get(reverse('polls.views.index'))
print response.context
print response.content
如你所见,我response.context['latest_poll_list']
的总是[]
所以我想知道我的错在哪里?