What you consider a canonical host reference has to be defined somewhere.
(Which combinations of those host references are actually usable is determined outside your Django project. For someone who does “https-only”, the last two are not valid, and for a group using multiple servers and subdomains, the first two could be different sites.)
All four version is valid in my case intentionally. So the same page can be accessed in 4 different ways. the www prefix is handled in DNS, the http/https is handled in nginx.conf by redirect. The only purpose I need canonical url to avoid duplicate content from SEO point of view.
So, my only goal is to put the following code to the head section of the templates:
I am looking for a way to use some context variables and create this. I do not think so that half hardcoding is “django friendly” and elegant solution like this: