16 lines
502 B
Python
16 lines
502 B
Python
from django.conf import settings
|
|
|
|
|
|
def canonical_url_processor(request):
|
|
if settings.DEBUG:
|
|
canonical_url = request.build_absolute_uri()
|
|
else:
|
|
current_host = request.get_host()
|
|
canonical_host = settings.CANONICAL_HOST
|
|
|
|
if current_host != canonical_host:
|
|
canonical_url = f"{request.scheme}://{canonical_host}{request.get_full_path()}"
|
|
else:
|
|
canonical_url = request.build_absolute_uri()
|
|
|
|
return {'canonical_url': canonical_url}
|