#34261: Use {% url model_object %} to work with get_absolute_url
--------------------------------------------+------------------------
Reporter: Willem Van Onsem | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 4.1
Severity: Normal | Keywords: url
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Django has a `{% url ... %}` tag to calculate a reverse url. The advantage
of this is that it raises an error in case the url can not be found, and
thus makes templates less buggy.m
An alternative is to define a `.get_absolute_url()` method on a model
object, and then use it in the template as `{{
model_object.get_absolute_url() }}`. If a model object however has no
`get_absolute_url` method, it will return an empty href, not an error.
We can combine the two and check if the first parameter has a
`get_absolute_url` method, if that is the case, we return the result of
`get_absolute_url` instead.
--
Ticket URL: <https://code.djangoproject.com/ticket/34261>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185b573b055-f594bcec-785b-4835-8621-d6538ecbfe6e-000000%40eu-central-1.amazonses.com.