所以我有一个名为notes的django网络应用程序,我有一个视图集。视图集由CRUD命令组成。当我为api创建测试时,它会重定向到不存在的url而不是Json String。这是我的代码:
对于tests.py:
def test_list(self):
e = Employee.objects.get(first_name="Dylan")
organ = Organization.objects.get(name='test')
cl = APIClient()
# cl = APIClient()
c = Customer.objects.get(first_name="John")
cl.credentials(HTTP_AUTHORIZATION='Token ' + organ.token.key)
response = cl.post('/api/notes/list', {'customer_id': c.uuid}, follow=True)
#cl.login(username = "Dylan", password="Snyder")
pprint("list: %s" % response.data)
表示api.py:
def list(self, request):
c = Customer.objects.get(pk=request.POST['customer_id'])
n = Note.objects.get(customer=c, retired=False)
notes = NoteListSerializer(n)
return HttpResponse(notes)
我得到的结果:
.'list: {\'detail\': \'Method "GET" not allowed.\'}'
在我使用的命令提示符中。我从来没有创建过目录或者包含/ details /的任何内容