def searchResult(request):
check()
query = request.GET.get('q')
print(query)
if request.GET.get('q') == '':
messages.error(request, "Please type something to search")
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
object_lists = Product.objects.filter(category=query)
context = {
'object':object_lists
}
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
在测试此视图时如何测试URL。我一直在使用以下内容进行测试,但:
url = reverse("search")
resp = self.client.get(url,data={'q':'Games'})
self.assertEqual(resp.status_code, 200)
我收到此错误。
ValueError:视图website.views.searchResult没有返回HttpResponse对象。而是返回None。
我如何进行正确的测试却没有收到此错误?