Django 2.2.10
django-hosts 4.0
I have installed django_hosts successfully as per this documentation.
I can successfully now access pages like https://blog.mysite.com
However, the urls on the page are NOT resolved correctly. I have followed the example shown in the django_hosts official documentation.
This is what my setup looks like:
mysite/urls.py
# imports etc. truncated for brevity
# ...
urlpatterns = [
path('', include(('home.urls', 'home'), namespace='home')),
path('blog/', include('blog.urls', namespace="blog")),
# ...
]
home/urls.py
from django.urls import path
from django.conf.urls import include, url
from .views import HomePageView, AboutView, TermsView, PrivacyView, \
sample, register, signin
app_name = 'home'
urlpatterns = [
path('', HomePageView.as_view(), name='index'),
path('about', AboutView.as_view(), name='about'),
path('terms', TermsView.as_view(), name='terms'),
path('privacy', PrivacyView.as_view(), name='privacy'),
path('sample', sample),
path('register', register, name='register'),
path('signin', signin, name='signin'),
]
blog/templates/index.html
<div class="container">
116 <!-- Logo -->
117 <a class="logo" href="{% host_url 'home' host 'www' %}" style="text-decoration: none; font-size: 250%;">
118 <img src="/static/assets/img/logo.png">
119 My Site
120 </a>
121 <!-- End Logo -->
[[ Edit ]]
The actual demo is uploaded to github
below how i managed to solve the issue
in
mysite/settings.py
in
mysite/hosts.py
in
mysite/urls/home.py
in
mysite/urls/blog.py
in
blog/templates/index.html