Wagtail links provides a consistent way to refer to links in a wagtail page.
pip install wagtail-links==2.7.0
Wagtail links has two goals:
pip install wagtail-links
wagtail_links
to INSTALLED_APPS./manage.py migrate
Add a foreign key to the page you wish to add links to.
my_link = models.ForeignKey(
'wagtail_links.Link',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
Neat:
You may use it like:
<a href="{{self.link.url}}">Link here</a>
The Link model will validate that one and only one field is set. It will also disallow invalid django reverse view names.
If a url cannot be determined, we'll log the issue as a warning. We won't error as that would be bad for users. You are responsible for capturing this standard python warning, perhaps use Sentry.
For example - let's say you make a django view name called admin:index. This would typically give you /admin/
.
Later the admin app is removed from the program, now this link fails. It will now display "" and make a warning.