Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How properly use reverse in tests?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

from django.urls import reverse

url = reverse("product-detail", kwargs={"pk": 4})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading