Skip to main content

django-multiurl

CI PyPI

Have you ever wanted multiple views to match to the same URL? Now you can.

You may once have tried something like this:

urlpatterns = [
    path("app/<str:name>/", app.views.people),
    path("app/<str:name>/", app.views.place),
]

However, if you try this, /app/san-francisco/ will only map to app.views.people. Raising an Http404 from app.views.people doesn't help: you only get a 404 in the browser because Django stops resolving URLs at the first match.

Well, django-multiurl solves this problem. Just pip install django-multiurl, then do this:

from django.urls import path
from multiurl import multiurl

urlpatterns = [
    multiurl(
        path("app/<str:name>/", app.views.people),
        path("app/<str:name>/", app.views.place),
    ),
]

Now in your views, raise multiurl.ContinueResolving anywhere you'd like to break out of the view and keep resolving. For example, here's what app.views.people might look like:

from multiurl import ContinueResolving


def people(request, name):
    try:
        person = Person.objects.get(name=name)
    except Person.DoesNotExist:
        raise ContinueResolving
    return render(...)

That's it! ContinueResolving will cause multiurl to continue onto the next view (app.views.place, in this example).

A few notes to round things out:

  • If you don't want to use ContinueResolving (perhaps you'd rather keep using get_object_or_404, or you're using third-party views that you can't modify to raise ContinueResolving), you can pass a catch argument into multiurl to control which exceptions are considered "continue" statements. For example, to allow Http404 exceptions to continue resolving, do this:

    urlpatterns = [
        multiurl(
            path("app/<str:name>/", app.views.people),
            path("app/<str:name>/", app.views.place),
            catch=(Http404, ContinueResolving),
        ),
    ]
    

    As you can see, catch should be a tuple of exceptions. It's probably a good idea to always include ContinueResolving in the tuple.

  • If the last view in a multiurl raises ContinueResolving (or another "continuing" exception), a 404 will be raised instead. That is, if resolving "falls off the end" of some multi-urls, you'll get the 404 you expect.

  • path() and re_path() both work, as does nesting multiurl inside include() (namespaces and captured prefix arguments are passed through).

  • Async views work, and can be mixed with sync views in one multiurl.

  • @csrf_exempt and @login_not_required are honored only when every view in the multiurl has them, since middleware runs before it's known which view will answer.

  • Reverse URL resolution just works as expected. Name your sub-URLs and then reverse your heart out.

Supported versions

django-multiurl Python Django
2.x 3.10 – 3.14 4.2, 5.2, 6.0, 6.1
1.x 2.7, 3.4+ 1.11 – 3.2

Contributing

Development takes place on GitHub; pull requests are welcome. The project uses uv:

uv run pytest                                      # run the tests
uv run --with "django==5.2.*" pytest               # against a specific Django
uv run ruff check . && uv run ruff format --check . && uv run ty check

PR titles must follow Conventional Commits (fix: …, feat: …, feat!: … for breaking changes): PRs are squash-merged and release-please uses the titles to pick the next version and write the changelog.

Metadata

Release files for django-multiurl 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-multiurl 2.0.0
File Size Uploaded Provenance Actions
django_multiurl-2.0.0.tar.gz 7.6 kB Without provenance Details for django_multiurl-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-multiurl 2.0.0
File Interpreter ABI Platform Actions
django_multiurl-2.0.0-py3-none-any.whl Python 3 none any Details for django_multiurl-2.0.0-py3-none-any.whl

Total release size: 13.2 kB

Release files / django_multiurl-2.0.0.tar.gz

Download URL django_multiurl-2.0.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bc4f0f328bf2248af9e9523e836220a31be9464ff98a0f2653a576071a59d612
BLAKE2b-256 checksum
How to use checksums
7c26352c6ad560ea05370b575f093beb1628a659b26fc3c640887267525f710c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_multiurl-2.0.0-py3-none-any.whl

Download URL django_multiurl-2.0.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd54ed4fc3411dcc61271fbb05db277685af24c36f90c35a0663351eafd33d1f
BLAKE2b-256 checksum
How to use checksums
b1b61351777d7d5e17de63795ce60fd24081d7aa86507664667b701a6863dd95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for django-multiurl 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page