Home > Net >  How properly use reverse in tests?
How properly use reverse in tests?

Time:11-10

There are SimpleRouter with ViewSet:

router = SimpleRouter()
router.register(r'product', ProductViewSet)

When i trying to write some tests for get endpoint: If i use url = reverse('product-list'), then i have url product/ and this is what i want. But after all product API i want to test product/pk/ api but i don't find the proper reverse in django rest framework Docs, can you help me?

CodePudding user response:

from django.urls import reverse

url = reverse("product-detail", kwargs={"pk": 4})
  • Related