1

When I have an urls.py file like this:

# urls.py
router = SimpleRouter(trailing_slash=False)
router.register("/?", MembersController, basename="member")
urlpatterns = router.urls

Then the generated URL for the single object is (?P<pk>[^/.]+)$. I'd like for it to include the int: "converter type". Is that possible at all? Or would I have to stop using DRF's router and create my own URL patterns?

1 Answer 1

1

In your MembersController you can specify the '[0-9]+' as lookup_value_regex:

class MembersController(ModelViewSet):
    lookup_value_regex = '[0-9]+'
    # ⋮

as default it makes use of '[^/.]+', as we can see in the source code [GitHub]:

lookup_value = getattr(viewset, 'lookup_value_regex', '[^/.]+')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the quick and helpful answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.