[Fixed]-Django Rest Framework reverse and SimpleRouter


YPCrumble, you would want to call the URL with distinct kwargs. The URL regex works in a way to handle kwargs. So for example:

# python reverse url
url = reverse('games-detail', kwargs={'team_pk': 1, 'group_pk':1})

# url regex


The issue seems to be related to the use of named groups in URL patterns. Using the args parameter in the reverse function, it’s causing a conflict with the named groups in URL pattern.

To address this issue, we can use the kwargs parameter in the reverse function to pass the values for the named groups. Here’s example:

url = reverse('games-detail', kwargs={'team_pk': team.pk, 'pk': game.pk})

For more comprehension:

  1. reverse in rest_framework
  2. router in rest_framework

Leave a comment