Opened 4 hours ago

Closed 3 hours ago

#36091 closed New feature (duplicate)

add absolute_url template tag

Reported by: sblondon Owned by:
Component: Template system Version: 5.1
Severity: Normal Keywords:
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 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.

Change History (1)

comment:1 by Tim Graham, 3 hours ago

Resolution: duplicate
Status: newclosed
Summary: add absolute_url template ?add absolute_url template tag

Duplicate of #10944.

Note: See TracTickets for help on using tickets.
Back to Top