urlman
A nicer way to do URLs for Django models.
Replaces things like get_absolute_url with a .urls attribute that can reference other URLs and build sensible trees of things, and can then be accessed using instance.urls.name.
This is so you can have URLs on your model instances directly (rather than reversing through the url lookup functions, which is not only slow but often hard to supply arguments to). You can just throw {{ instance.urls.view }} into a template to get a link.
It also lets you use Python string formatting syntax to place arguments into URLs from the model instance itself or from other URLs in the same set.
Example:
import urlman
class Group(models.Model):
...
class urls(urlman.Urls):
view = "/{self.slug}/"
users = "{view}users/"
admin = "{view}admin/"
def my_view(request):
group = ...
return redirect(group.urls.view)
It’s suggested that you use “view” as the equivalent name for get_absolute_url, and have a function like this on your model:
def get_absolute_url(self):
return self.urls.view
To build a full URL use the full method like this:
def my_view(request):
group = ...
return redirect(group.urls.admin.full(scheme='https'))
You can implement the get_scheme(url) and get_hostname(url) methods on your Url class to change your default theme and hostname from the urlman defaults of ‘http’ and ‘localhost’, respectively.
If you use Django REST Framework, you can use urlman.UrlManField to provide an object with a set of URLs. It is used like this (only the urls parameter is required):
from urlman.serializers import UrlManField
class MySerializer(ModelSerializer):
urls = UrlManField(urls=['view', 'edit'], attribute='urls', full=True)
Metadata
Release files for urlman 2.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| urlman-2.0.3.tar.gz | 12.0 kB | Without provenance | Details for urlman-2.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| urlman-2.0.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for urlman-2.0.3-py2.py3-none-any.whl |
Total release size: 23.6 kB
Release files / urlman-2.0.3.tar.gz
| Download URL | urlman-2.0.3.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40fe1b181914a61f0547e6686235b60fd74f325396bcaf1cdd0b63260e2984ae
|
|
BLAKE2b-256 checksum How to use checksums |
968498b4475229b1fd611a4b60bfa456bc139357698958288ee096c02568e0fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / urlman-2.0.3-py2.py3-none-any.whl
| Download URL | urlman-2.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9712a0be2893b3032ab29478a15a7af19fec02fdb2ed33dd13fde478958b7fc0
|
|
BLAKE2b-256 checksum How to use checksums |
9fcd5ab829b7c17c11e7654cd51fd6607b19cd03d5a81cb0985ae1c4000e9deb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for urlman 2.0.3
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.