Set canonical_url domain in settings
This commit is contained in:
parent
4a282ba7a8
commit
00d8a792d0
2 changed files with 20 additions and 0 deletions
|
@ -32,6 +32,9 @@ LOCALE_PATHS = [
|
|||
BASE_DIR / 'locale',
|
||||
]
|
||||
|
||||
# Hostname for canonical_url
|
||||
CANONICAL_HOST = "nyymix.net"
|
||||
|
||||
|
||||
# Application definition
|
||||
INSTALLED_APPS = [
|
||||
|
@ -76,6 +79,7 @@ TEMPLATES = [
|
|||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'gallery.context_processors.canonical_url_processor',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
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