[Django] #36091: add absolute_url template ?

4 views
Skip to first unread message

Django

unread,
Jan 12, 2025, 4:34:54 PM1/12/25
to django-...@googlegroups.com
#36091: add absolute_url template ?
--------------------------+-------------------------------------------
Reporter: sblondon | Type: New feature
Status: new | Component: Template system
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+-------------------------------------------
Django provides 'Model.get_absolute_url()' and template tag '{% url %}' to
create URLs in templates.
'{% url %}' is usable on every path if 'name' parameter is defined.
Unfortunately, Django does not provide a way to create an absolute URL (if
not based on Model) in template. This needs occurs regularly.

Of course, it's possible to write something like '{{ base_url }}{{ url
"app.name" }}' with some setup.

A cleaner way is to set up a 'absolute_url' template tag.

People shows implementations of such template tag like:
https://stackoverflow.com/questions/52193142/how-to-generate-absolute-
urls-in-django-2-templates
https://stackoverflow.com/questions/19024159/how-to-reverse-a-name-to-a
-absolute-url-in-django-template

Someone already created a library for this need 11 years ago:
https://github.com/bartgryszko/django-absoluteurl

I think it would be better to include it inside Django.
What do you think about it?

I can a PR with test and documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/36091>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages