redirect and canonical tag

This commit is contained in:
Tobias Brunner 2025-03-03 14:39:57 +01:00
parent 26064d749c
commit b836d38e70
No known key found for this signature in database
4 changed files with 50 additions and 0 deletions

View file

@ -1,10 +1,12 @@
{% load static %}
{% load canonical_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Servala - {% block title %}{% endblock %}</title>
<link rel="canonical" href="{% canonical_url %}" />
<link rel="icon" type="image/x-icon" href="{% static "img/favicon.ico" %}">
<link rel="stylesheet" href='{% static "css/bootstrap-icons.min.css" %}'>

View file

@ -0,0 +1,18 @@
from django import template
from django.conf import settings
from urllib.parse import urljoin
register = template.Library()
@register.simple_tag(takes_context=True)
def canonical_url(context):
"""
Returns the canonical URL for the current page
"""
request = context["request"]
path = request.path
# Construct the canonical URL using the WEBSITE_URL from settings
canonical = urljoin(settings.WEBSITE_URL, path)
return canonical