#34261 closed New feature (wontfix)
Use {% url model_object %} to work with get_absolute_url
Reported by: | Willem Van Onsem | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 4.1 |
Severity: | Normal | Keywords: | url |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (2)
comment:1 by , 2 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Uncategorized → New feature |
comment:2 by , 2 years ago
Well the confusion started for me... when redirect
accepts a model object, and {% url ... %}
does not... :P
Thanks for this ticket, however, IMO this syntax would be really confusing for users as it mixes URL resolvers and model methods. It would also unnecessarily complicate an existing Django code.
Please first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow the guidelines with regards to requesting features.