嗨,我有这样的看法:
def AjaxPopulate(request):
colour = request.GET.get('colour_id')
if colour is None:
return HttpResponseBadRequest()
qs = Thing.objects.select_related()
things = get_list_or_404(qs, colour=colour)
data = []
for x in things:
data.append({
'id': x.id,
'name': unicode(x),
})
return HttpResponse(simplejson.dumps(data), mimetype='application/json'
与此网址挂钩:
url(r'^ajax_populate/$', 'colours.views.AjaxPopulate', name='ajax_populate'),
在我的测试中,我有:
def setUp(self):
self.client = Client()
user = User.objects.create_superuser('foo', 'myemail@test.com', 'bar')
colour1 = Colour.objects.create(colour='Green')
thing1 = Thing.objects.create(name='Leaf', colour=colour1, description='foo')
def test_ajax_populate(self):
response = self.client.get('/colours/ajax_populate/', {'colour_id': 1})
self.assertEqual(response.status_code, 200)
但是,我收到一个AssertionError: 404 != 200
错误。
我究竟做错了什么?
非常感谢任何帮助。