Django Navbar No Reverse Match error - how do I fix this?

I'm receiving the below error when trying to link up my navbar in base.html in Django.

NoReverseMatch at / 'home' is not a registered namespace

I'm not sure why it's not working, any help would be much appreciated!

base.html:

          <ul class="nav navbar-nav ms-auto">
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'home:home' %}"><strong>Home</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'home' %}"><strong>My Health</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'login' %}"><strong>Login</strong></a></li>
                                <li class="nav-item"><a class="nav-link text-white" href="{% url 'signup' %}"><strong>Signup</strong></a></li>
                            </ul>

urls.py:

urlpatterns = [
    path('', views.home, name='home'),
    path('signup/', views.signup, name='signup'),
    path('login/', views.login, name='login'),
    path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url("favicon.ico"))),
    path('success/', views.success_view, name='success'),
]

views.py:

def home(request):
    return render(request, 'HealthHub/home.html')

In your urls.py you should modify this line:

 <li class="nav-item"><a class="nav-link text-white" href="{% url 'home' %}"><strong>Home</strong></a></li>

If you write home:home django looks for an app_name called home in your urls.py file.

Back to Top