pageurl can do it with a Page object, but I am not sure how to get the root page object.
The URL of the root page is /
. Just write <a href="/">
- no need to use a template tag.
(You might think that's cheating, but it's literally the definition of the root page.)
If you have your include(wagtail_urls)
line in urls.py rooted at a path other than /
, and don't want to hard-code that path in your template, you can use: {% url 'wagtail_serve' '' %}
(note the empty string after 'wagtail_serve'
).
re_path(r'^blog/', include(wagtail_urls)),
I tried {% url 'wagtail_serve' %}
, but it gives error: Reverse for 'wagtail_serve' with no arguments not found. 1 pattern(s) tried: ['blog/((?:[\\w\\-]+/)*)$']
–
Harrus wagtail_urls
seems to be deprecated. See updated answer with new tags tag. –
Sponger If you use wagtail_modeltranslation and want to get the translated root page url (eg: example.com/fr/ for French), you can use {% pageurl request.site.root_page %}
.
For wagtail versions > 2.9:
{% load wagtailcore_tags %}
{% wagtail_site as current_site %}
Then either use {% pageurl current_site.root_page %}
or {{ current_site.root_url }}
.
To show the site root page in a wagtail template, add the following to your page template:
{% load wagtailcore_tags %}
<a href="{{ request.site.root_url }}">Site Url</a>
This code is deprecated. Starting with wagtail 2.9, the preferred option is {% wagtail_site %}
. View wagtail 2.9 release notes
{{ page.get_site.root_url }}
–
Brougham With wagtail version > 2.12.2 you need to import {% wagtail_site as current_site %}
and then you can use: {{ current_site.root_url }}
in your template.
If you use wagtail-localize this will get you the homepage for your current locale
{% pageurl page.get_site.root_page.localized %}
The most recent version of Wagtail, 5.1.1, you can use the {% url 'wagtail_serve' '' %}
template tag.
For example, in html it would be written:
<a class="footer-links" href="{% url 'wagtail_serve' '' %}">Blog</a>
wagtailcore_tags
before using the {% url %}
tag, because {% url %}
is a standard tag built into Django, not part of Wagtail. (You might have other things on the template that require wagtailcore_tags
, though.) –
Mic include(wagtail_urls)
. –
Sponger © 2022 - 2025 — McMap. All rights reserved.