I am really getting to the end of my tether with django-hosts
I want to redirect cerulix.com/blog → blog.cerulix.com. But apparently that’s way too much of an ask.
Here’s my MRE:
I install the django-hosts module in my .venv by running the following command:
pip install django-hosts
#settings.py
MIDDLEWARE = [
'django_hosts.middleware.HostsRequestMiddleware',
'django_hosts.middleware.HostsResponseMiddleware',
]
INSTALLED_APPS = [
'blog',
'django_hosts'
]
ALLOWED_HOSTS = [
'127.0.0.1',
'cerulix.com',
'www.cerulix.com',
'blog.cerulix.com',
]
ROOT_HOSTCONF = "cerulix.hosts"
DEFAULT_HOST = "www"
PARENT_HOST = 'cerulix.com'
#cerulix.hosts
from django_hosts import patterns, host
from django.conf import settings
from django.urls import path, include
host_patterns = patterns('',
host(r'www', settings.ROOT_URLCONF, name='www'),
host(r'blog', 'blog.urls', name='blog')
)
#cerulix.urls
from . import views
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
urlpatterns = [
path('', views.index),
path('blog', include('blog.urls'), name='blog'),
]
#blog.urls
from django.urls import path
from. import views
urlpatterns = [
path('', views.blog, name='blog'),
path('<slug:slug>', views.blog__details),
]
#index.html
{% load hosts %}
<a href="{% host_url 'blog' host 'blog' %}" >Blog</a></li>
As you can see, everything is set up correctly.
Guess what?
- You type
blog.<domain>.cominto the URL, →index.html - You go to the
blog<a href=">link, it does go to the blog, but the URL in the address bar isblog.cerulix.com/blog. How absolutely stupid can this thing be? - You then click off of the blog to go to another page, guess what, the address in the URL bar is - yup, you guessed it -
blog.cerulix.com
So why? My configurations are correct, so why?
You have zero idea how sick to the back teeth I am of this.