Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reversing URLs with multiple operations. #638

Merged
merged 2 commits into from Feb 22, 2023

Conversation

strange
Copy link
Contributor

@strange strange commented Dec 22, 2022

A pretty glaring shortcoming is that it is impossible to reverse URLs that have been registered with same path, but different operations.

Using the same path for different operations is a pretty common pattern. It is even used throughout Ninja's documentation.

@router.get("/{identifier}")
def detail(request, identifier: str):
    return "ok"

@router.put("/{identifier}")
def update(request, identifier: str, data: Policy):
    return "ok"

The above is perfectly valid, but reversing update using django.urls.reverse() will result in a NoReverseMatch error.

This commit is an attempt at solving the issue. N.B. I am not familiar with the internals of Ninja.

A pretty glaring shortcoming is that it is impossible to reverse URLs
that have been registered with same path, but different operations.

Using the same path for different operations is a pretty common pattern.
It is even used throughout Ninja's documentation.

    @router.get("/{identifier}")
    def detail(request, identifier: str):
        return "ok"

    @router.put("/{identifier}")
    def update(request, identifier: str, data: Policy):
        return "ok"

The above is perfectly valid, but reversing `update` using
`django.urls.reverse()` will result in a `NoReverseMatch` error.

This commit is an attempt at solving the issue. N.B. I am not familiar
with the internals of Ninja. This is just an experiment.
@vitalik vitalik merged commit 7527193 into vitalik:master Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants