django subdomains error namespace does not exist

35 Views Asked by At

Trying to configure subdomains. ie. two.example.com default domain www.example.com but getting error "app_two is not a registered namespace" via {% url 'app_two:app-two-list' %} in base.html

I've also tried {% host_url 'app-two-list' host 'two' %} but it redirects to just two and not two.example.com

project urls.py

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("app_one.urls", namespace="app_one")),
]

app_one urls.py

app_name = "app_one"

urlpatterns = [
   path("", views.home, name="home")
]

app_two urls.py

app_name = "app_two"

urlpatterns = [
    path("", AppTwoListView.as_view(), name="app-two-list"),
    path("new/", AppTwoCreateView.as_view(), name="app-two-create")
]

project hosts.py

host_patterns = [
    host("www", settings.ROOT_URLCONF, name="www"),
    host(
        "two",
        include("app_two.urls", namespace="app_two"),
        name="two"
    ),
]

project setting.py

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.sites",
    "django.contrib.redirects",
    "django_hosts",
    "app_one",
    "app_two",
]

MIDDLEWARE = [
    "django_hosts.middleware.HostsRequestMiddleware",
...
    "django_hosts.middleware.HostsResponseMiddleware",
]

ROOT_URLCONF = "project.urls"
ROOT_HOSTCONF = "project.hosts"
DEFAULT_HOST = "www"
SITE_ID = 1

projects base.html

{% load static %}
{% load hosts %}
    <nav>
        <a class="navbar-brand" href="{% url 'app_one:home' %}">
            <img src="{% static 'app_one/svg/logo.svg' %}" alt="App One Logo" height="30">
        </a>
        <a class="nav-link" style="color:#ffff"
            href="{% url 'app_two:app-two-list' %}">two</a>    
    </nav>
0

There are 0 best solutions below