How do I pass a PK or slug to a DetailView using RequestFactory in Django?

前端 未结 1 1295
离开以前
离开以前 2021-02-03 21:05

I\'m trying to use RequestFactory to test a DetailView with the following test case:

def test_device_homepage(self):
    request = self.factory.get(\'/devices/1/         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-03 21:29

    Thanks to the #django channel on Freenode IRC, I found the following method is the correct one to pass parameters all the way through to the view:

    response = DeviceView.as_view()(request, pk=1)
    

    I hope this helps somebody else attempting to use RequestFactory to test DetailView or DeleteView etc

    0 讨论(0)
提交回复
热议问题