#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.
--
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 visit
https://groups.google.com/d/msgid/django-updates/010701945c70e1c6-ff4bf0ea-bb83-4325-bf50-627b50055ef4-000000%40eu-central-1.amazonses.com.