Set canonical_url domain in settings
This commit is contained in:
parent
4a282ba7a8
commit
00d8a792d0
2 changed files with 20 additions and 0 deletions
16
gallery/context_processors.py
Normal file
16
gallery/context_processors.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
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}
|
Loading…
Add table
Add a link
Reference in a new issue